zoukankan      html  css  js  c++  java
  • 让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;
    }
    }
    }


    在全站搜索一下$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

  • 相关阅读:
    Linux系统常用工具集
    Storm安装部署
    Linux下搭建Elasticsearch7.6.2集群
    解决SpringMVC @RequestBody无法注入基本数据类型
    微服务概念
    HashMap的原理简单介绍
    mysql进阶
    vue 路由缓存 keep-alive include和exclude无效
    el-date-picker 时间日期格式,选择范围限制
    RedisTemplate使用rightPushAll往list中添加时的注意事项
  • 原文地址:https://www.cnblogs.com/wawahaha/p/4709531.html
Copyright © 2011-2022 走看看