First, determine if you are logged in,
if (Isset ($_session[' user_id ')) {
Exist
Add the user ID and product ID to the shopping cart table
}else{
Do not exist; Use cookies to put the commodity ID and host IP into an array
, the array is stored in a cookie, and the browser is allowed to store 300 cookies,
Each cookie is 4KB large enough to meet the requirements of the shopping cart and
Reduced load on the server
}
If the browser disables the cookie, use Memcache to implement
Another way to determine whether to log in,
if (Isset ($memcache->get (' user_id '))) {
Exist
Add the user ID and product ID to the shopping cart table
}else{
does not exist;
$memcache = new Memcache (); Instantiate Memchche
$data =[' goods_id ' = $goods _id, ' IP ' =>$_server
[' REMOTE_ADDR '];
$memcache->set (' key key ', serialize ($data));
}
There is no big difference between REDIS implementations and Memcache!
Both of these methods can be implemented, if you use the first, we have to
Set the expiration time of the cookie, if the second type is used, the value
You need to deserialize the unserialize (), and then you can get the
The Data!
PHP Simple implementation of shopping cart