|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27050 Can't Read Cookie From Class Constructor
Submitted: 2004-01-26 11:16 UTC Modified: 2004-02-01 00:11 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: design at laneforestproducts dot com Assigned:
Status: No Feedback Package: Session related
PHP Version: 5.0.0b3 (beta3) OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
40 + 8 = ?
Subscribe to this entry?

 [2004-01-26 11:16 UTC] design at laneforestproducts dot com
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));

		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
if (empty($_COOKIE['PHPSESSID'])) {			
		$_SESSION['lfp_user'] = new lfp_user();	
// kill session and reload page again to see nothing in 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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-26 20:10 UTC]
First of all, are you really using PHP 5? Have you tried PHP 4.3.4 ?

And what do you mean with 'kill session' ??

 [2004-01-27 11:03 UTC] design at laneforestproducts dot com
Yes, I am using php 5... Don't worry, it only exists in our dev sandbox =) But I am very excited at this new turn for php!

About Kill Session: I meant to close your browser and then reload the page to get a new session, thus firing the creation of a new lfp_user object. I would expect a new phpsessid to be generated, and the lfp_guid to be found on the client's box when the object is instantiated. Instead, the lfp_guid cookie is never found. The print_r is there as the lazy approach to actually checking your cookies: you can open the page then refresh to explode the cookie array onto your screen, although I suppose lfp_user does some echo's too.

Thanks for the quick response! ~Andrew
 [2004-01-27 15:56 UTC]
Please try using this CVS snapshot:
For Windows:

 [2004-02-01 00:11 UTC]
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Mar 28 21:03:37 2023 UTC