MV framework logo
  • Architecture
    • Philosophy
    • Technologies
  • Admin Panel
  • Changelog
  • Support
  • Feedback
Download Version 2.6 from 07.10.2022
Documentation
  • Architecture
    • Philosophy
    • Technologies
  • Admin Panel
  • Changelog
  • Support
  • Feedback
Getting started
  • Installation and launch
  • System folders
  • Launch of simple website
  • Pre-installed models
  • System settings
Models
  • General principles of models
  • Data types
  • Model settings
  • Simple models
  • Foreign keys
  • Trees
  • Many to many
  • Group
  • Records management
  • Simple model management
  • Additional options
Views and routes
  • General principles of views
  • Router object
  • MV object
  • Index, default and 404 templates
  • Creating a new template
  • Data display in template
  • Object of Record class
  • Files and images
  • Date and time
  • Redirects
  • Email delivery
  • Special methods
Forms
  • Forms creation
  • Form fields settings
  • Form validation rules
  • Form validation process
  • Operations with form data
  • Using data from models
  • Form methods
SQL queries
  • Query constructor
  • Direct queries
  • Pagination
  • Sorting
  • Filtration
  • Upload from CSV files
Sessions and security
  • Work with sessions
  • AJAX
  • Security
  • Debugging
Plugins
  • General principles of plugins
  • Additions to admin panel
  • Caching
Documentation
Getting started
  • Installation and launch
  • System folders
  • Launch of simple website
  • Pre-installed models
  • System settings
Models
  • General principles of models
  • Data types
  • Model settings
  • Simple models
  • Foreign keys
  • Trees
  • Many to many
  • Group
  • Records management
  • Simple model management
  • Additional options
Views and routes
  • General principles of views
  • Router object
  • MV object
  • Index, default and 404 templates
  • Creating a new template
  • Data display in template
  • Object of Record class
  • Files and images
  • Date and time
  • Redirects
  • Email delivery
  • Special methods
Forms
  • Forms creation
  • Form fields settings
  • Form validation rules
  • Form validation process
  • Operations with form data
  • Using data from models
  • Form methods
SQL queries
  • Query constructor
  • Direct queries
  • Pagination
  • Sorting
  • Filtration
  • Upload from CSV files
Sessions and security
  • Work with sessions
  • AJAX
  • Security
  • Debugging
Plugins
  • General principles of plugins
  • Additions to admin panel
  • Caching

Work with sessions

Standard PHP sessions support

To make MV start a session on the frontend, you need to turn on the option in "config/setup.php" file. In this case a standard PHP session will start, and its values will be available in a global "$_SESSION" array.

'SessionSupport' => true

Fields with CAPTCHA check

When there are "char" type fields with the captcha parameter in a form, you will see an image with characters which need to be entered in text box. And validation of input occurs on the server when the form is submitted.

When the image with characters is generated, the characters will be placed into a session for future check.

//Create a form from a model for clients registration 
$form = new Form("Clients");

//Add a field for checking code 
$form -> addField(array("Security code ", "char", "captcha", array("captcha" => "extra/captcha-simple/")));
$form -> addRule("captcha", "required", true, "Mandatory to fill");

In "extra/captcha-simple/index.php" file an image is created and shown symbols are placed into a session. You may change the color of symbols or background there.

<?
session_start();
 
//Generation of string of symbols and image 
...
 
imagegif($img); //Display an image 
 
$_SESSION["captcha"] = $string; //Save the code for the form validation
?>

When validating a filled form, data is taken from a session for check.

if(!empty($_POST))
{
    $form -> getDataFromPost() -> validate();
 
    if($form -> captcha)
        if(!isset($_SESSION["captcha"]) || $_SESSION["captcha"] != $form -> captcha)
          $form -> addError("Not a valid security code", "captcha");
 
    if($form -> isValid())
    {
        ...
    }
}

Previous section

Upload from CSV files

Next section

AJAX

© 2012-2023, MV framework

MV tracker is based on open source MV framework
License