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
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.

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.