tags:

views:

102

answers:

3

Im having problems with session variable after my database have changed the session variable, it doesnt update the new session variable when i press the back button but on database, it already updated but not on the webpage, i have to relogin to see the new variable.

and how do i use session_regenerate_id?

+1  A: 

Copied from php.net:

<?php
session_start();

$old_sessionid = session_id();

session_regenerate_id();

$new_sessionid = session_id();

echo "Old Session: $old_sessionid<br />";
echo "New Session: $new_sessionid<br />";

print_r($_SESSION);
?>
r3zn1k
A: 

Make sure that you have put below statement on top of your script otherwise no sessions will be handled:

session_start();
Sarfraz
If this was the actual problem, I think I will smash my fist into the wall.
Chacha102
Calm yourself, Chacha. Hola said that the data is there in the DB, so the session has to have been started, right?
pib
of coz session have already started -_-
Hola
@Pib I apologize for that remark. I do realize now that my sarcasm was probably not played off well considering that someone might not know to use 'session_start()' to be able to use the data. In hindsight, it could have been the problem.
Chacha102
+1  A: 

When a user presses the back button, their browser generally shows a cached page, rather than re-requesting the page, so that's most likely where your issue is coming from.

You use session_regenerate_id by calling it... and the user will be given a new session ID and their session will be transfered over to that ID, if you pass True as a parameter, the session will be cleared, too. It's generally used to prevent session fixation attacks

pib
but when i press refresh on the page, it still doesnt change the variable, any ideas to solve tis?
Hola