Jump to content

session vars (simple counter)


voodoochicken

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

It works fine for me. You may run into problems if you're testing on localhost, cookies do not work properly in some browsers when the domain is localhost or another domain without a normal TLD.
tnx for your help, the problem seems to be the save session path was pointing to a non existing dir
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...