$this->_ip = real_ip(); 注释,换成下面代码//购物车 by neo
if(isset($_COOKIE['real_ipd']) && !empty($_COOKIE['real_ipd']))
{
$this->_ip = $_COOKIE['real_ipd'];
}
else
{
$this->_ip = real_ip();
setcookie("real_ipd", $this->_ip, time()+864000, $this->session_cookie_path);
}继续找function destroy_session() 把里面的setcookie($this->session_name, $this->session_id, 1, $this->session_cookie_path, $this->session_cookie_domain, $this->session_cookie_secure);
if (!empty($GLOBALS['ecs']))
{
$this->db->query('DELETE FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '$this->session_id'");
} 都注释掉。这是退出登录的时候,删除cookie,删除购物车的" WHERE session_id NOT " . db_create_in($valid_sess); 改成" WHERE add_time < ".($time-86400*30)." AND session_id NOT " . db_create_in($valid_sess);管理员登陆时不清空购物车。function update_user_info() 在函数最里面加入//购物车 by neo
$sql = "update ".$GLOBALS['ecs']->table('cart')." set user_id =".$_SESSION['user_id']." where session_id = '".SESS_ID."'";
$GLOBALS['db'] -> query($sql);
$sql1 = "update ".$GLOBALS['ecs']->table('cart')." set session_id ='".SESS_ID."' where user_id = '".$_SESSION['user_id']."'";
$GLOBALS['db'] -> query($sql1);
$re = $GLOBALS['db'] -> getAll("select *,sum(goods_number) as goods_number from ".$GLOBALS['ecs']->table('cart')." where user_id = '{$_SESSION['user_id']}' and session_id = '".SESS_ID."' group by goods_id");
if($re)
{
foreach ($re as $k => $v)
{
$sql = "update ".$GLOBALS['ecs']->table('cart'). " set goods_number = ".$v['goods_number']." where rec_id = ".$v['rec_id'];
$GLOBALS['db'] -> query($sql);
$sql = "delete from ".$GLOBALS['ecs']->table('cart')." where rec_id <> {$v['rec_id']} and user_id = '{$_SESSION['user_id']}' and session_id = '".SESS_ID."' and goods_id = ".$v['goods_id'];
$GLOBALS['db'] -> query($sql);
}
}会员到别处登录,获取之前的购物车商品出来。
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。