Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The sessions on PHP works with a Cookie type session, while on server-side the session information is constantly deleted.</p> <p>For set the time life in php, you can use the function <a href="http://php.net/manual/es/function.session-set-cookie-params.php" rel="noreferrer">session_set_cookie_params</a>, before the session_start: </p> <pre><code>session_set_cookie_params(3600,"/"); session_start(); </code></pre> <p>For ex, 3600 seconds is one hour, for 2 hours 3600*2 = 7200.</p> <p>But it is session cookie, the browser can expire it by itself, if you want to save large time sessions (like remember login), you need to save the data in the server and a standard cookie in the client side.</p> <p>You can have a Table "Sessions":</p> <ul> <li>session_id int</li> <li>session_hash varchar(20)</li> <li>session_data text</li> </ul> <p>And validating a Cookie, you save the "session id" and the "hash" (for security) on client side, and you can save the session's data on the server side, ex:</p> <p>On login:</p> <pre><code>setcookie('sessid', $sessionid, 604800); // One week or seven days setcookie('sesshash', $sessionhash, 604800); // One week or seven days // And save the session data: saveSessionData($sessionid, $sessionhash, serialize($_SESSION)); // saveSessionData is your function </code></pre> <p>If the user return:</p> <pre><code>if (isset($_COOKIE['sessid'])) { if (valide_session($_COOKIE['sessid'], $_COOKIE['sesshash'])) { $_SESSION = unserialize(get_session_data($_COOKIE['sessid'])); } else { // Dont validate the hash, possible session falsification } } </code></pre> <p>Obviously, save all session/cookies calls, before sending data.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload