Answer the question
In order to leave comments, you need to log in
Old data in php session variables, why not updated?
Hello, there are problems with php session variables.
The structure is as follows:
- conn.php (database connection and global variables);
- index.php (a form with POST data input, and transferring data to session variables or deleting files from the session);
- page1.php
-page2.php
-page3.php.
On pages page1-3, I retrieve data from the database based on user data from the session. But now it looks like after I went through all the pages as User1 , after which I logged out and entered as User2 , but on pages page2 and page3 the old data of User1 is displayed, his data is stored in the session, and are updated only after the page is refreshed.
On pages page1-3 I use session data $user=$_SESSION["user"];
When I log out, I delete session data (variables and session), I tried to clear everything as much as possible:
$_SESSION["user"] = '';
unset($_SESSION['user']);
...
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
...
session_write_close();
setcookie(session_name(),'',0,'/');
session_unset();
session_destroy();
session_regenerate_id(true);
with all this, when you log out of the account, on the index.php page (redirect after logout), the logs show that the session is empty, there is nothing. But, as I described the problem, on the page pages, the data in the session is old.
I understand that the problem can be not only in clearing the session data, but also with connecting the session in files? Everywhere I start the file with session_start () and 'require con.php', in require con.php I also connect the session and write the data from the session to variables. Is a session collision possible, or something else - what could be the problem, how to avoid them?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question