Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetCookie() Problem

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi there,

I Have the following code:

<?
$loginUserName = &quot;Ali&quot;;
setcookie (&quot;CkUserName&quot;, $loginUserName, time()+3600, &quot;/&quot;, &quot;.127.0.0.1&quot;,1);
$CkUserName = $HTTP_COOKIE_VARS[&quot;CkUserName&quot;];
echo &quot;UserName: $CkUserName&quot;;
?>

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?
 
What do you mean by pearing down?

As I mentioned before, the cookie is set successfully, I can browse the cookie in &quot;My Computer&quot; under Cookies folder (WinXP) and all the data is there! But when I try the code:

$CkUserName = $HTTP_COOKIE_VARS[&quot;CkUserName&quot;];
echo &quot;UserName: $CkUserName&quot;;

Its not working!

Any help
 
&quot;Paring down&quot;...

Notice my line of code. I did not set all of the parameters available, just the first three.

Cookies are squirrely things, particularly on IE. Those extra parameters may be keeping IE from returning the cookie on successive requests. Want the best answers? Ask the best questions: TANSTAAFL!
 
I edited the code and its working fine only the first time the cookie is created with this code:

<?
$loginUserName = &quot;Ali&quot;;
setcookie (&quot;CkUserName&quot;, $loginUserName, time()+3600, &quot;/&quot;, &quot;.127.0.0.1&quot;,0);
$CkUserName = $HTTP_COOKIE_VARS[&quot;CkUserName&quot;];
echo &quot;UserName: $_COOKIE[CkUserName]&quot;;
?>

But if I change the code for the variable $loginUserName to:

$loginUserName = &quot;Ali123&quot;;

STRANGE!!! Still give me the old cookie value &quot;Ali&quot;.

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?
 
This is the reason that the &quot;Remember my login&quot; feature of the Tek-Tips login sends you to an intermediate page. The intermediate page ensures that the cookie is set and ready to be returned before you enter the site. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top