Jump to content

Archived

This topic is now archived and is closed to further replies.

lilywong

PHP Cookies problem

Recommended Posts

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

×

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.