#27050 [Opn->Fbk]: Can't Read Cookie From Class Constructor

From: Date: Tue, 27 Jan 2004 01:10:52 +0000
Subject: #27050 [Opn->Fbk]: Can't Read Cookie From Class Constructor
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-53931@lists.php.net to get a copy of this message
ID: 27050 Updated by: sniper@php.net Reported By: design at laneforestproducts dot com -Status: Open +Status: Feedback -Bug Type: *General Issues +Bug Type: Session related Operating System: Windows 2000 PHP Version: 5.0.0b3 (beta3) New Comment: First of all, are you really using PHP 5? Have you tried PHP 4.3.4 ? And what do you mean with 'kill session' ?? Previous Comments: ------------------------------------------------------------------------ [2004-01-26 11:16:22] design at laneforestproducts dot com Description: ------------ With the code below, the expected function is that a returning user with the 'lfp_guid' cookie will be recognized when the cookie is read. However, the lfp_guid is never found again after creation and a new lfp_guid is created at the beginning of each session. Reproduce code: --------------- class lfp_user { var $guid; function lfp_user() { if (isset($_COOKIE['lfp_guid'])) { $this->guid =$_COOKIE['lfp_guid']; } else { $this->guid = md5(uniqid(rand(0,1)*100,true)); setcookie("lfp_guid",$this->guid,time()+60*60*24*365*2,"","127.0.0.1",true); } echo "LFP_USER.constructor: _COOKIE['lfp_guid']== '".$_COOKIE['lfp_guid']."'<br>"; echo "LFP_USER.constructor: GUID == ".$this->guid."<br>"; //echo isset($_COOKIE['lfp_guid'])."<br>"; } // end constructor } // end class session_start(); if (empty($_COOKIE['PHPSESSID'])) { $_SESSION['lfp_user'] = new lfp_user(); } // kill session and reload page again to see nothing in cookie: print_r($_COOKIE); Expected result: ---------------- Since the lfp_guid cookie is actually set on the user's machine, $_COOKIE would access this list and store it in the new object. Actual result: -------------- A new lfp_guid is created and set on the user's machine no matter what. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27050&edit=1

« previous php.bugs (#53931) next »