A session of PHP
safely saves the user name, login status, and other things in the $_SESSION
matrix, since it is stored on the server. The only thing that is sent to the browser is a cookie
only (called PHPSESSID unless you have changed it php.ini ) that contains the ID
of the session, which is a unique random number.
Once your visitor has an active session each time you request a page that has session_start()
at the top, session_start()
will see the request for a cookie
called PHPSESSID
, read the session file of the server (if the session exists and is valid) and will restore the $_SESSION
archived set. This matrix never needs to leave the server.
The% session% co is set without an expiration date (unless you hit the cookie
option in php.ini ) , so that the browser deletes it when shutting down. The session file on the server has an expiration time, managed by session.cookie_lifetime
(in seconds).
On the road to safer sessions:
You can see more information about sessions and security here .
What you should not do in a secure login system
You can set the random_bytes()
with the cookie
function or within your session_set_cookie_params
.
session_set_cookie_params($lifetime = 0, $path = '/', $domain, $secure = true, $httponly = true);
Finally, you should create a script to register users outside the session (and encourage them to use it instead of just browsing). This is a sample script:
<?php
session_start();
$params = session_get_cookie_params();
setcookie(session_name(), '', 1, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));
session_regenerate_id(true);
session_destroy();
session_write_close();
header('Location: your_login_page.php');
exit;
Also after a successful login or logout, change the session ID :
session_regenerate_id();
to close the session:
session_regenerate_id(true);
This publication explains in theory the following Source and Gatekeeper that implements it.
source
Now you can investigate further.