Jump to content


Photo

PHP Cookies problem


  • Please log in to reply
3 replies to this topic

#1 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 15 July 2006 - 06:01 AM

I am doing a website something like online shopping system, anyone allows to browse my website and add cart (before log in), and the item added will be store using cookies, so user are allow to view their shopping basket even he has not log in yet.

However, if a user finally decided to buy the selected item in the shopping basket, he will then need to log in, if he is a new user he will need to register, else just simply put his username and password. After log in, i decided to use Session to keep the user ID and selected item, is it possible to do that ? is it possible to use cookies to keep user preference before log in, and change to use Session to keep user preference after log in?

I'm wondering, please advice. thanks.

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 15 July 2006 - 11:20 AM

yes, it's possible to use cookie to maintain user's references before login.
cookies and session provided storage of data on client and server respectively.
Life's too short for arguing.

#3 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 15 July 2006 - 03:24 PM

anyone can show a single example about capture a user preference using cookies?
or any link i can see the source code for my references ?

thank you so much !

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 16 July 2006 - 12:04 AM

to set a cookie:
setcookie ("TestCookie", $value, time()+3600);  /* expire in 1 hour */

to get the cookie:
echo $_COOKIE["TestCookie"];

you must do cookie setting before sending any header information

Life's too short for arguing.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users