...

View Full Version : Get and Set Cookies



ScottInTexas
04-04-2003, 09:49 PM
Can someone answer this or point me to a source of info? How do you save a cookie to the user's computer and how do you read that cookie when they open the web site?

x_goose_x
04-04-2003, 09:55 PM
Try a basic search...

http://www.google.ca/search?q=php+cookies&ie=UTF-8&oe=UTF-8&hl=en&meta=

missing-score
04-04-2003, 11:06 PM
// This goes before the <html> tag

setcookie('cookiename','cookie info',time()+3600);

// time() + 3600 is the expiration. time()+3600 would be 1 hour ( 3600 seconds )


That would set a cookie to the users computer, that would last the set time. To display the contents of the cookie, you need to use $HTTP_COOKIE_VARS ( or $_COOKIE )




// an example, set a cookie then get its value

setcooke('name','matt',time()+300)

// sets a cookie called name, with a value of matt that lasts 5 minutes.

echo $_COOKIE['name'];

// would write matt on to the page.

ScottInTexas
04-05-2003, 01:04 PM
Thanks a lot for the answers.

missing-score
04-05-2003, 01:10 PM
no prob :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum