Session Handling with Recess!

I use the Recess Framework for my application and worry about session processing. I need to save some values ​​in a session. I can create a session id and session id. But as soon as I go to another page, I can’t get them back! How do you manage people? Processing PHP sessions is simple and straightforward .. but I'm just not able to get it right!

In my home controller, I have:

/* !Route GET, / */
function index() {
   .
   .
   session_start();
   $_SESSION['val'] = 'SomeValue';
   .
   .
}

My view displays a different form, and when the user submits, I also need to access the val session. Therefore, I am trying to return a value like:

/* !Route GET, /check */
function check() {
    if(isset($_SESSION['val'])){
       .
       .
       .
    }       
}

But, unfortunately, I do not enter the if block. I don’t see my error. I tried to display the session using session_id (), as well as its empty value in the check () method.

, , , session_id ! PHP? , !

+3
2

Recess, :

session_start() recess-conf.php, !

+1

-, :

http://snipplr.com/view/41338/start-a-secure-session/

function startSession($session_name) {
    session_name($session_name);
    $ok = @session_start();
    if(!$ok){
       session_regenerate_id(true); // replace the Session ID
       session_start(); // restart the session (since previous start failed)
    }
}

session_start(); .

/* !Route GET, /check */
function check() {
    session_start();
    if(isset($_SESSION['val'])){
       .
       .
       .
    }       
}

function startSession($session_name) {
    session_name($session_name);
    $ok = @session_start();
    if(!$ok){
       session_regenerate_id(true); // replace the Session ID
       session_start(); // restart the session (since previous start failed)
    }
}

/* !Route GET, / */
function index() {
   .
   .
   startSession('SID'); // SID is only for example you can use what you want
   .
   .
   $_SESSION['val'] = 'SomeValue';
   .
   .
}


/* !Route GET, /check */
function check() {
       .
       .
       .
    startSession('SID'); // SID is only for example you can use what you want
       .
       .
       .
    if(isset($_SESSION['val'])){
       .
       .
       .
    }       
}
0

Source: https://habr.com/ru/post/1790937/


All Articles