voodoochicken Posted February 14, 2008 Share Posted February 14, 2008 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 More sharing options...
justsomeguy Posted February 14, 2008 Share Posted February 14, 2008 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 More sharing options...
voodoochicken Posted February 14, 2008 Author Share Posted February 14, 2008 hmm.. i copy-pasted your suggestion in a new document, but i keep getting '2' when i reload the page Link to comment Share on other sites More sharing options...
AElliott Posted February 14, 2008 Share Posted February 14, 2008 Are you accepting cookies from the page? It could be the session ID cookie not being set. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 14, 2008 Share Posted February 14, 2008 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. Link to comment Share on other sites More sharing options...
voodoochicken Posted February 14, 2008 Author Share Posted February 14, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.