Jump to content

[SOLVED] Issues with Cookies


pugboy

Recommended Posts

Currently, I am making a citation generator for school. I am also adding a feature to save your citations into a "document".

 

I store a 30 day cookies with a random string, but if I want to access the string right after the cookie is created, it doesn't show up. How would I get the cookie to show up on the page, or how do I communicate a variable ($docid) from one set of <?php ?> tags to another farther down the page?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/105367-solved-issues-with-cookies/
Share on other sites

Ahhh.....

 

When you call setcookie(), what PHP does in the long run is it sends a header to the web client telling it to set a cookie a certain way.

 

Then, the next time that client connects to the same webserver, if it has a cookie, it may offer it up to the webserver saying, "Hey, I have a cookie with these values."

 

PHP parses the cookie values into a convenient $_COOKIE super global array, but it is only parses the next time around due to the nature of sending the header.

 

So

 

setcookie('corbin', 'isawesome'); //bad example of a cookie set but oh well.

 

does not automatically set $_COOKIE['corbin'] to "isawesome."  If all goes well, it will be on the next load that PHP will parse that cookie value.

 

So, how do you get the "isawesome" value later in the script?  Simply store what you're storing ;p.

 

$value = "Hi, this is the cookie's value.";

 

setcookie('name', $value);

 

echo "The cookie was set to hold {$value} in name.";

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.