Page 1 of 1
SetCookie() Problem
Posted: Fri Feb 14, 2003 9:30 am
by alsaffar
Hi there,
I Have the following code:
<?
$loginUserName = "Ali";
setcookie ("CkUserName", $loginUserName, time()+3600, "/", ".127.0.0.1",1);
$CkUserName = $HTTP_COOKIE_VARS["CkUserName"];
echo "UserName: $CkUserName";
?>
The cookie set successfully, but I can't retrieve the information from it! (echo is not showing the data from the cookie I set).
Please any help?
Posted: Fri Feb 14, 2003 9:35 am
by oldtimer
Try this
Code: Select all
<?php
echo "$_COOKIE["CkUserName"]";
?>
Yor need that $_COOKIE.
Posted: Fri Feb 14, 2003 9:44 am
by alsaffar
Thank you oldtimer for your help,
Its working fine only the first time the cookie is created with this code:
<?
$loginUserName = "Ali";
setcookie ("CkUserName", $loginUserName, time()+3600, "/", ".127.0.0.1",0);
$CkUserName = $HTTP_COOKIE_VARS["CkUserName"];
echo "UserName: $_COOKIE[CkUserName]";
?>
But if I change the code for the variable $loginUserName to:
$loginUserName = "Ali123";
STRANGE!!! Still give me the old cookie value "Ali".
Also if I delete the cookie from Cookies folder (WinXP) still it gave me the old value, although I checked that data in the new cookie is Ali123 but still with echo it gave me only Ali!!!
Any Idea?
Thank you
Posted: Mon Feb 17, 2003 2:13 am
by twigletmac
Have you read the documentation on
setcookie()?
PHP manual wrote:Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE).
Mac