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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a cookie script

Status
Not open for further replies.

theoneweasel77

Programmer
Joined
Aug 10, 2004
Messages
54
Location
US
I need a short, simple script that creates a cookie, and checks for the existance of that cookie. And I don't want the cookie to expire for a long time. I've been trying to do this, but I can't figure it out. Just something short. create. test. done. thanks in advance.
 
You can't do that in one script. You need two, one to set it and one to check it.

This is because you can't deterministically test for the presence of the cookie until it has been sent back to the server from the browser on the next script run.



For example code for setting a cookie, see the online manual entry for setcookie(). The page has an in-depth explanation and example code.


To see whether a cookie exists in the next script, use print_r() on the $_COOKIE superglobal array


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I don't care if it necessarily works the first time, I just need an example of a script setting a cookie and testing for it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top