标签:
让Ecshop网店系统用户户自动登陆,打开ecshop includes/init.php文件,可以发现Ecshop系统判断用户的SESSION不存在的时候会去读取存储在COOKIES里面的值。如下代码片段所示:
if (empty($_SESSION[‘user_id‘]))
{
if ($user->get_cookie())
{
/* 如果会员已经登录并且还没有获得会员的帐户余额、积分以及优惠券 */
if ($_SESSION[‘user_id‘] > 0)
{
update_user_info();
}
}
else
{
$_SESSION[‘user_id‘] = 0;
$_SESSION[‘user_name‘] = ‘‘;
$_SESSION[‘email‘] = ‘‘;
$_SESSION[‘user_rank‘] = 0;
$_SESSION[‘discount‘] = 1.00;
if (!isset($_SESSION[‘login_fail‘]))
{
$_SESSION[‘login_fail‘] = 0;
}
}
}
在全站搜索一下$user->logout();方法。可以在includes/modules/integrates/integrate.php文件中找到如下代码:
function set_cookie($username=‘‘, $remember= null )
{
if (empty($username))
{
/* 摧毁cookie */
$time = time() - 3600;
setcookie("ECS[user_id]", ‘‘, $time, $this->cookie_path);
setcookie("ECS[password]", ‘‘, $time, $this->cookie_path);
}
elseif ($remember)
{
/* 设置cookie */
$time = time() + 3600 * 24 * 15;
setcookie("ECS[username]", $username, $time, $this->cookie_path, $this->cookie_domain);
$sql = "SELECT user_id, password FROM " . $GLOBALS[‘ecs‘]->table(‘users‘) . " WHERE user_name=‘$username‘ LIMIT 1";
$row = $GLOBALS[‘db‘]->getRow($sql);
if ($row)
{
setcookie("ECS[user_id]", $row[‘user_id‘], $time, $this->cookie_path, $this->cookie_domain);
setcookie("ECS[password]", $row[‘password‘], $time, $this->cookie_path, $this->cookie_domain);
}
}
}
将
$time = time() - 3600;
setcookie("ECS[user_id]", ‘‘, $time, $this->cookie_path);
setcookie("ECS[password]", ‘‘, $time, $this->cookie_path);
三行代码注释掉后,退出系统将不再清楚user_id和password的COOKIE了,这样用户登录的时候只要这两个COOKIE值存在就会自动显示为登录状态。
转载:http://www.ecshoptemplate.com/article-1841.html
标签:
原文地址:http://www.cnblogs.com/wawahaha/p/4709531.html