本文实例讲述了php购物车实现方法。分享给大家供大家参考。具体分析如下:
这里我们为你提供个简单的php购物车代码,从增加购物产品与发生购买了,在商城开发中,这个功能是少不了的,我们不需要数据库,用了txt文本文件来操作用户购物的内容.
增加商品到购物车,代码如下:
//
// add_item.php:
// Add an item to the shopping cart.
//
session_start();
if (session_is_registered('cart')) {
session_register('cart');
}
require 'lib.inc.php'; // LoadProducts()
LoadProducts(); // Load products in $master_products_list
// Make $curr_product global
$curr_product = array();
// Loop through all the products and pull up the product
// that we are interested in
foreach ($master_products_list as $prod_id => $product) {
if (trim($prod_id) == trim($_GET[id])) {
$curr_product = $product;
}
}
// Register our session
//session_r