It took me several times to run this code. But nothing seemed to work out. My server is Apache latest version and have php 5.x.x. It does not work out what i wanted. <?php session_start(); if(!session_is_registered("count")) { session_register("count"); session_register("start"); $count=0; $start=time(); } else { $count++; } $sessionId=session_id(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><title>Sessions</title></head> <body> <p>This page points at a session (<?=$sessionId?>)<br/> count=<?=$count?>.<br/> start=<?=$start?>. <p>This session lasted <?php $duration=time()-$start; echo "$duration"; ?> seconds. </body> </html> PHP:
There are local variables and session variables, the session variables are stored in the $_SESSION array on the server, the local variables you can use on the fly. when you use variables stored in the $_SESSION array, you copy the sessionvariable count to the local variable count $count=$_SESSION[count']; perform some operations on the local variable $count++; and store the local var count back to the sessionvariable $_SESSION['count']=$count; if(!isset($_SESSION['count'])) { $count=0; $_SESSION['count']=$count; $start=time(); $_SESSION['start']=$count; } else { $count = $_SESSION['count']; $count++; $_SESSION['count'] = $count; } $sessionId=session_id(); PHP: (I use isset() in stead of session_is_registered.) In your code snippet else { $count++; } PHP: there is no copy of the $_SESSION array variable count to the local variable $count, that one starts fresh at 0 and gets 1 added so you always get 1 as value.
Should i set session.save_path = "C:/WINDOWS/TEMP" in my php.ini? I am using Apache for windows. Is this the place where sessions are saved?
session.save_path = "c:/windows/temp" works fine, you can put any directory in php.ini as long as it is writable, the cookies are saved on the location you enter in php.ini you can use \\ when you want to access a win32 file system in php code c:\\windows\\temp\\