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?
SetCookie() Problem
Moderator: General Moderators
Try this
Yor need that $_COOKIE.
Code: Select all
<?php
echo "$_COOKIE["CkUserName"]";
?>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
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
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Have you read the documentation on setcookie()?
MacPHP 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).