Can someone tell me why I can't retrieve cookie information inside an object? Is this a bug in php5 or am I doing something wrong here?
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);
$_COOKIE['lfp_guid']= $lfp_guid;
}
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();
session_register(); // is this necessary?
if (empty($_COOKIE['PHPSESSID'])) {
$_SESSION['lfp_user'] = new lfp_user();
}
// reload page again to see nothing in cookie:
print_r($_COOKIE);
If you open your cookies, you will see that it did work, but PHP can't retrieve the info.
Thanks!
Andrew