Jump to content

Cookie problem


Larry101

Recommended Posts

I am using this to set the script.. test.php

 

<?PHP

setcookie("user1", "Alex Porter", time()+3600);

echo "Cookie Set (supposeably!)<br />";


echo "OK....... ";


?>

 

and then I am using this script to retrieve the info (I am running it from a seperate browser session)... test1.php

 


<?PHP

$the_date = date("m/d/y: H:i:s",$timestamp);


if (isset($_COOKIE["user1"]))
  echo "Welcome " . $_COOKIE["user1"] . "!<br />";
else
  echo "Welcome guest!<br />";
  
  print_r($_COOKIE);

echo "OK....... ";


?>

 

But it fails to pick up the cookie data plus I can't physically find a cookie in the files.

Link to comment
https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051442
Share on other sites

supposeably? lol, very nice.

 

Can you make the following changes?

 

Replace:

setcookie("user1", "Alex Porter", time()+3600);

 

With:

$cookie = setcookie("user1", "Alex Porter", time()+3600);

echo $cookie? 'woot!' : 'omg fail';

 

Tell me what that prints out.

 

The output was

 

woot!Cookie Set

OK......

 

 

When I run test1.php I get this....

 

Welcome guest!

Array ( [logintheme] => cpanel [cprelogin] => no [cpsession] => closed ) OK.......

Link to comment
https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051447
Share on other sites

hallelujah...  solved it... thanks for your help Ken2k7 you pointed me in the right direction.

 

Coz I haven't been on PHP for a few years I was trying to retrieve the variable without using the $_COOKIE["    "]. When I implemented that into the actual script I was trying to fix it fixed the problem.

 

:D :D 8)

Link to comment
https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051527
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.