php购物车实现方法
|
本文实例讲述了php购物车实现方法。分享给大家供大家参考。具体分析如下: 这里我们为你提供个简单的php购物车代码,从增加购物产品与发生购买了,在商城开发中,这个功能是少不了的,我们不需要数据库,用了txt文本文件来操作用户购物的内容. 增加商品到购物车,代码如下: 代码如下: require 'lib.inc.php'; // LoadProducts()
LoadProducts(); // Load products in $master_products_list // Make $curr_product global // Loop through all the products and pull up the product foreach ($master_products_list as $prod_id => $product) { // Register our session if ($_POST[ordered]) { // If they have chosen the product array_push($_SESSION[cart][products],array(trim($_POST[id]),$_POST[quantity])); 添加至购物篮成功<a href="cart.php">返回 商品列表页面. 添加 到您的购物篮<form action="<?php echo $PHP_SELF; ?>" method="post"> 查看购物车的商品,代码如下: 代码如下: require 'lib.inc.php'; //判断购物篮会话变量cart是否注册,不注册则注册cart变量 if (session_is_registered('cart')) { session_register('cart'); } // 如果购物篮没有初始化,则初始化购物篮 欢迎进入网上商店<?php 当前在购物篮里的物品
相关内容
推荐文章
站长推荐
热点阅读
|
