Forum Moderators: coopster

Message Too Old, No Replies

Cookies within a class

         

kindacheezy

10:48 pm on Jan 5, 2003 (gmt 0)

10+ Year Member



I wrote this script to handle user's info. When i call setUser() it allways prints no if the cookie is there or not.

?php
//A PHP script that can set a Cookie read the Cookie and send the information to A script
class User
{
var $user="abe"; //Store's user's name
var $userName;
var $set;
function User($inName,$useName)
{
$this->userName=$inName;
$this->set=$useName;
}
function setFile() //Take's in a string and sets a cookie
{
$path="/php/"; //Sets the path the cookie can be read from (not used yet)
$time=time() + 400000000000000; //Sets the time when the Cookie will die at (not used yet)
$site="somesite.com"; //Sets the site name that set the Cookie (not used yet)
setcookie('name',$this->userName); //Sets the Cookie
}

function getUser()//sends back $user
{
return $this->user;
}

function setUser() //Sets value to $user
{
if($HTTP_COOKIE_VARS['name'])
{
$name=$HTTP_COOKIE_VARS['name'];
echo"$name";
}
else
{
echo"no";
}

}
}
?>

If i put

if($HTTP_COOKIE_VARS['name'])
{
$name=$HTTP_COOKIE_VARS['name'];
echo"$name";
}
else
{
echo"no";
}

in its own file it works fine.
Any one have any ideas?

[edited by: jatar_k at 7:27 pm (utc) on Jan. 6, 2003]
[edit reason] removed specifics [/edit]

andreasfriedrich

12:24 am on Jan 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com] kindacheezy.

You need to define $HTTP_COOKIE_VARS as global.

[php.net...]

Or better yet use the $_COOKIE [php.net] super global array.

Andreas

kindacheezy

3:56 am on Jan 6, 2003 (gmt 0)

10+ Year Member



Thanks It worked!