Getting started


Views and routes


SQL queries

Sessions and security



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.

//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.

    $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())