setcookie() and session handling

From: Date: Fri, 18 Oct 2002 02:50:57 +0000
Subject: setcookie() and session handling
Groups: php.general 
Request: Send a blank email to php-general+get-120455@lists.php.net to get a copy of this message
Hello, I'm experiencing a problem with setcookie(). I uploaded exactly the same PHP file to two different servers. One has PHP v3.0.15 while the other has PHP v4.1.2. The code that was uploaded in PHP3 works while the one ulpoaded in PHP4 does not. Here's the code: // start code snippet for script that sets cookie // call a function that returns random session id $sessioncontext = generate_sessionid(); $sessionexpiration = 3600; // 1 hour // set the first cookie setcookie("sessioncontext", $sessioncontext, time() + $sessionexpiration); $userid = 1; // originally, this is taken from a db // set the second cookie setcookie("userid", $userid, time() + $sessionexpiration); // end first code snippet // start code snippet for script that checks session $sessionexpiration = 3600; if ($sessioncontext) { // reset cookie expiration } else { // redirect to error page then log in } // end second code snippet These two script work fine in the server that has PHP3 but not in the one with PHP4. Can somebody please tell me what I'm doing wrong? My second request from the list is to point me to examples on how to use the session handling functions of PHP4. I have seen the ones in the manual but I'd like to see more complete examples. Thanks. -- Ric Manalac

« previous php.general (#120455) next »