How to write PHPcookie + shopping cart ?? -Php Tutorial

Source: Internet
Author: User
How to write PHPcookie + shopping cart ?? I will not write it here when I create a website to make a shopping cart !! Please refer to the highly handwritten code !! Thank you.


Reply to discussion (solution)

The one that cannot store cookies, and the user will log on to the favorites next time to find the items in the shopping cart.

Ajax + database storage content.

I am also in need of shopping cart information, 2 floor said AJax + database is how to achieve, if you have the source code to share... thank you!

 ";   //print_r($cars_id);//echo"
"; // Exit; foreach ($ cars_id as $ pr_id) {if ($ pr_id = $ product_id) {echo" script alert ('you have purchased this product, check the shopping cart! '); Location. href = 'Car. php'; script "; exit; }}if (empty ($ _ COOKIE [buypro]) {setcookie (" buypro ", $ product_id, time () + 3600); setcookie ("buycount", "1", time () + 3600);} else {$ newpro = $ _ COOKIE [buypro]. ",". $ product_id; $ newcount = $ _ COOKIE [buycount]. ",". "1"; setcookie ("buypro", $ newpro, time () + 3600); setcookie ("buycount", $ newcount, time () + 3600 );}} // delete if ($ act = "del") {$ buy = $ _ COOKIE [buypro]; $ cars_id = explode (",", $ buy ); $ buycountary = explode (",", $ _ COOKIE [buycount]); $ newid = array (); $ carcount = array (); for ($ I = 0; $ I

Learning

Share you a full set of points, which are not enough.

// Index. php
  
  
 
"Width =" 123 "height =" 121 "border =" 0 "/> Goods name:
Goods price:
& Pname = "> Purchase
// Conn. php // Car. php
Item ID Item Quantity Unit Price Total price Delete
"> Delete
  Total price S
Submit the order // return to the home page // buy. php $ Pid, "price" = >$ price, "num" => 1) ;}} else {$ arr [$ pid] = array ("pid" => $ pid, "price" => $ price, "num" => 1);} $ _ SESSION ["mycar"] = $ arr; // after the purchase, put this array into the session again, and you can see this sessionob_clean (); // clear the cache header ("location: car. php "); // jump to the shopping cart page (car. php)?>


It may not be very powerful, but it is a basic skill. You can modify it as required.

How to write thinkPHP shopping cart code

Learning

A user who has not logged on to the shopping cart stores items in cookies and has logged on to the database

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.