Larry101 Posted April 30, 2010 Share Posted April 30, 2010 Can anyone see anything wrong with this code? I just cant seem to get it to work and I've tried it on 2 PC's :'( <?PHP setcookie("user1", "Alex Porter", time()+3600); echo "Cookie Set <br />"; echo "OK....... "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/ Share on other sites More sharing options...
Ken2k7 Posted April 30, 2010 Share Posted April 30, 2010 What's wrong with the code? Do you mean the cookie isn't being set or are the echos not working? Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051180 Share on other sites More sharing options...
Larry101 Posted April 30, 2010 Author Share Posted April 30, 2010 What's wrong with the code? Do you mean the cookie isn't being set or are the echos not working? Sorry.. the cookie doesn't seem to be setting. Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051233 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 What's wrong with the code? Do you mean the cookie isn't being set or are the echos not working? Sorry.. the cookie doesn't seem to be setting. How are you verifying that? Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051428 Share on other sites More sharing options...
Larry101 Posted May 1, 2010 Author Share Posted May 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051442 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051443 Share on other sites More sharing options...
Larry101 Posted May 1, 2010 Author Share Posted May 1, 2010 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....... Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051447 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 Wait, what do you mean when you run test1.php? Where are the files located? Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051465 Share on other sites More sharing options...
Larry101 Posted May 1, 2010 Author Share Posted May 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/200303-cookie-problem/#findComment-1051527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.