Problem with $HTTP_COOKIE_VARS[$ck]

I have 3 programs:
1. ShowCookie.php
<?php
function ShowCK()
{
$ck = $HTTP_COOKIE_VARS["ka"];
return $ck;
}
?>

2. SetMyCookie.php
<?php
setcookie("ka", "kimanh");
?>
<html>
<head>
<title>Set my cookie</title>
</head>

<body>
<a href=http://www.htmlforums.com/archive/index.php/"xem.php">Xem cookie </a>
</body>
</html>

3. ShowMyCookie.php
<?php
include('ShowCookie.php');
?>
<html>
<head>
<title>Show my cookie</title>
</head>

<body>
Cookie: <?php ShowCK();?>
</body>
</html>

Problem is: function ShowCK() (in ShowCookie.php) did not return any value.

Why?
$HTTP_COOKIE_VARS can not return true value where it is in included program (include ('ShowCookie.php'))?it looks to me like this line:

Cookie: <?php ShowCK();?>

should be:

Cookie: <?php echo ShowCK();?>


but your setcookie line might need more parameters too, like the time and the path and the domain.

try this:

<?php
setcookie("aa", "kimanh", time()+3600);
?>

if the cookie still will not write you may need to add the path and domain parameters.

<?php
setcookie("aa", "kimanh", time()+3600, "/yourpath/", ".yourdomain.com", 0);
?>hmm... someone else can explain this, but when I use:

$HTTP_COOKIE_VARS

no value is returned using your scripts, but when I use:

$_COOKIE

the value is returned. Maybe you already know that.

<?php
setcookie ("TestCookie", "test", time()+3600, "/~e-pixsco/", "host43.ipowerweb.com", 0);
?>
<html>
<head>
<title>Set my cookie</title>
</head>
<body>
<a href=http://www.htmlforums.com/archive/index.php/"ShowMyCookie.php">Show cookie</a>
</body>
</html>

<?php
include('ShowCookie.php');
?>
<html>
<head>
<title>Show my cookie</title>
</head>
<body>
Cookie: <?php echo ShowCK();?>
</body>
</html>

<?php
function ShowCK()
{
$ck = $_COOKIE["TestCookie"];
return $ck;
}
?>that is becasue these 2 scripts.


1. ShowCookie.php
<?php
function ShowCK()
{
$ck = $HTTP_COOKIE_VARS["ka"];
return $ck;
}
?>

2. SetMyCookie.php
<?php
setcookie("aa", "kimanh");
?>
<html>
<head>
<title>Set my cookie</title>
</head>

<body>
<a href=http://www.htmlforums.com/archive/index.php/"xem.php">Xem cookie </a>
</body>
</html>

when he setcookie he called the cookie "aa" but when you tried to echo it out you wanted "ka", that would't show the cookie that was just set.

also using $HTTP_COOKIE_VARS is deprecated and the super global $_COOKIE is preffered.Good catch scoutt, aa and ka.

Even when I tried my own names, I could not get the cookie to print to the screen until I used $_COOKIE.

I did see that $HTTP_COOKIE_VARS was deprecated, so that explains its.

Cool, I guess I am starting to learn a bit of PHP :)this works for me

<?php
setcookie ("TestCookie", "test", time()+3600);
?>
<html>
<head>
<title>Show my cookie</title>
</head>
<body>
Cookie: <?php echo $HTTP_COOKIE_VARS["TestCookie"];?>
</body>
</html>

then jsut refresh that page.certainly that works great.

I like to stick with the scripts the person is trying to use because they may have a reason for using them like that or are trying to learn step by step.

Of cours showing a person how to reduce code and streamline a script is always good too.well that is true. but I don't believe there is anything that makes a person use 3 pages to do 1 function. but I do see what you mean.

so you didn't get it to work like he had it, after changing the code, like the wrong variable and echoing the ***ntion?

I will try it tonight or here in hour or so.I could not get it to work like he/she had it, but it would never work calling the wrong cookie. ;)

I do not know which version of PHP is on the server I tested the scripts on, but the variable $HTTP_COOKIE_VARS would not return anything even if all the rest of the code was right.I posted to this telling my reuslt bu tit is gone. oh well

my findings. it seems since the function is in another file(which really shouldn't matter) it doens't work. I turned on register_globals and the samething. but as soon as I put the function in the main file it works. I think that since the function is not getting the variables it isn't working.

but I couldn't get it working either
 
Back
Top