Heim >Backend-Entwicklung >PHP-Tutorial >ecshop保存登录名问题(每一次都取得前一次的值)
每次点击保存用户名,故意输错密码,然后会弹窗显示账号或密码错误,点击确定回到登录页面时,保存的用户名是上一次的(清空所有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>
前台代码
<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>
每次点击保存用户名,故意输错密码,然后会弹窗显示账号或密码错误,点击确定回到登录页面时,保存的用户名是上一次的(清空所有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>
前台代码
<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>
因为
<code>$reuser_name= isset($_COOKIE['ECS']['reuser_name']) ? $_COOKIE['ECS']['reuser_name'] : '';</code>
啊
改成
<code>$reuser_name= isset($_COOKIE['ECS']['reuser_name']) ? $_COOKIE['ECS']['reuser_name'] : ''; if (! empty($user_name)) $reuser_name = $user_name;</code>