Working 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 these sessions will be accessible 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 that need to be entered in a text box. And validation of input occurs on the on the server when the form is verified.

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

//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 -> getValue("captcha"))
        if(!isset($_SESSION["captcha"]) || $_SESSION["captcha"] != $form -> getValue("captcha"))
          $form -> addError("Not a valid security code", "captcha");
    if($form -> isValid())