Jump to content

session vars (simple counter)


voodoochicken
 Share

Recommended Posts

i am making a 'server side' counter, what you would normally do with cookies, to test persistence of session variables. there are two scripts: the one at the beginning where the session is open (so it can place the session id cookie before html) and registers the variable as a session variablethe second is the one that acts as a counter. the whole page is like this (copy-paste)

<?phpsession_start();if (!isset($estado_sesion)) {	$estado_sesion = 1;}session_register("estado_sesion");?><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php$estado_sesion += 1;echo $estado_sesion; ?></body></html>

it gets stuck in '2', so it is not counting, so i guess it is not saving the state of the var registered as a session var. any pointers?

Link to comment
Share on other sites

Registering session variables is deprecated behavior, there is a better way now. Instead of registering session variables, the preferred way is to use the $_SESSION array. If you do that then you don't need to register anything.

<?phpsession_start();if (!isset($_SESSION['estado_sesion'])) {	$_SESSION['estado_sesion'] = 1;}?><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php$_SESSION['estado_sesion'] += 1;echo $_SESSION['estado_sesion']; ?></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...