Home >Backend Development >PHP Tutorial >登录一刷新,php脚本弹出if话语里js对话框

登录一刷新,php脚本弹出if话语里js对话框

WBOY
WBOYOriginal
2016-06-13 10:31:54662browse

登录一刷新,php脚本弹出if语句里js对话框
if((isset($_POST['user'])&&$_POST['user']=='panus')&&(isset($_POST['password'])&&$_POST['password']=='welcome'))
  {
setcookie("dlcookie","ok");
echo ""; 
  }
   
  else{
echo "";
  }
为什么一刷新也会弹出(帐号或密码错误)js对话框??应该怎样修改?

------解决方案--------------------
提交到本页面? 你刷新一次等于重新执行一次文件,没满足if 条件,当然就进入else分支了。
------解决方案--------------------
代码的业务逻辑有问题啊,应该这样写:

PHP code
if(isset($_POST['user']) && isset($_POST['password'])) {    if ($_POST['user'] == 'panus' && $_POST['password'] == 'welcome') {        setcookie("dlcookie","ok");        echo "<script type="text/javascript">location.href='login.php'</script>";    }    else echo "<script type="text/javascript">alert('帐号或密码错误');</script>";}<br><font color="#e78608">------解决方案--------------------</font><br>最好将php代码写到另一个页面进行处理,可以避免页面刷新时的自动提交。可以了解一下MVC<div class="clear">
                 
              
              
        
            </div>
Statement:
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