实现Ecshop网店系统用户自动登录

实现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;
            }
        }
    }
打开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值存在就会自动显示为登录状态。

本文原创地址:https://www.ecshop.cx/article-569.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。

实时购买动态 ×

匿名网友 在 2019-04-14 购买了 ECSHOP确认收货同步分成免操作点击分成按钮 自动分成去掉二次操作问题