Home > Backend Development > PHP Tutorial > ecshop保存登录名问题(每一次都取得前一次的值)

ecshop保存登录名问题(每一次都取得前一次的值)

WBOY
Release: 2016-06-06 20:16:21
Original
1263 people have browsed it

每次点击保存用户名,故意输错密码,然后会弹窗显示账号或密码错误,点击确定回到登录页面时,保存的用户名是上一次的(清空所有cookie时,第一次跳回来是空值),不是当前的,什么问题啊,纠结好久了

后台代码

<code>$user_name = !empty($_POST['username']) ? $_POST['username'] : '';
$pwd = !empty($_POST['pwd']) ? $_POST['pwd'] : '';
$gourl = !empty($_REQUEST['gourl']) ? $_REQUEST['gourl'] : '';

$remember = isset($_POST['remember']) ? $_POST['remember'] : 0;
    //echo "<script type="text/javascript">alert('{$remember}');</script>";
//记住用户名字
if(!empty($remember)){
        setcookie("ECS[reuser_name]", $user_name, time() + 31536000, '/');
}
$reuser_name= isset($_COOKIE['ECS']['reuser_name']) ? $_COOKIE['ECS']['reuser_name'] : '';
   
if(!empty($reuser_name)){
    $smarty->assign('reuser_name', $reuser_name);
            
}</code>
Copy after login
Copy after login

前台代码

<code> <li class="liuser"><div class="liwrap"><input type="text" name="username" value="{$reuser_name}" class="text" placeholder="请输入用户名/邮箱/手机号"></div></li>

<li class="log"><div class="liwrap"><input type="password" name="pwd" class="text" placeholder="请输入密码"></div></li>

 <li class="remember_password">
  <div class="remember">
    <input type="checkbox" name="remember" id="remember" value="1">
    <span>记住用户名</span>
</div>
</li></code>
Copy after login
Copy after login

回复内容:

每次点击保存用户名,故意输错密码,然后会弹窗显示账号或密码错误,点击确定回到登录页面时,保存的用户名是上一次的(清空所有cookie时,第一次跳回来是空值),不是当前的,什么问题啊,纠结好久了

后台代码

<code>$user_name = !empty($_POST['username']) ? $_POST['username'] : '';
$pwd = !empty($_POST['pwd']) ? $_POST['pwd'] : '';
$gourl = !empty($_REQUEST['gourl']) ? $_REQUEST['gourl'] : '';

$remember = isset($_POST['remember']) ? $_POST['remember'] : 0;
    //echo "<script type="text/javascript">alert('{$remember}');</script>";
//记住用户名字
if(!empty($remember)){
        setcookie("ECS[reuser_name]", $user_name, time() + 31536000, '/');
}
$reuser_name= isset($_COOKIE['ECS']['reuser_name']) ? $_COOKIE['ECS']['reuser_name'] : '';
   
if(!empty($reuser_name)){
    $smarty->assign('reuser_name', $reuser_name);
            
}</code>
Copy after login
Copy after login

前台代码

<code> <li class="liuser"><div class="liwrap"><input type="text" name="username" value="{$reuser_name}" class="text" placeholder="请输入用户名/邮箱/手机号"></div></li>

<li class="log"><div class="liwrap"><input type="password" name="pwd" class="text" placeholder="请输入密码"></div></li>

 <li class="remember_password">
  <div class="remember">
    <input type="checkbox" name="remember" id="remember" value="1">
    <span>记住用户名</span>
</div>
</li></code>
Copy after login
Copy after login

因为

<code>$reuser_name= isset($_COOKIE['ECS']['reuser_name']) ? $_COOKIE['ECS']['reuser_name'] : '';</code>
Copy after login


改成

<code>$reuser_name= isset($_COOKIE['ECS']['reuser_name']) ? $_COOKIE['ECS']['reuser_name'] : '';
if (! empty($user_name)) $reuser_name = $user_name;</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template