在表单处理页面中的php部分添加了一句
echo "<script>location.href='login.php'</script>";
浏览器中访问login.php
结果居然是不断的打开那个url。
怎么解决?<html>
<meta http-equiv="content" content="text/html;charset=utf8">
<title>xxx</title>
</head>
<body>
<?php    $Pusername=$_POST[username];
    $Ppassword=$_POST[password];    setcookie('cid',$Pusername);
    setcookie('cpassword',$Ppassword);    //echo "<script>document.location.href='login.php'</script>";    if($_COOKIE[cid] && $_COOKIE[cpassword])
    {
        echo "id and password cookie has set!"."<br />";
        echo "用户名:".$_COOKIE['cid']."密码:".$_COOKIE['cpassword']."<br />";
    }
?>
<form action="" method="POST">
<div><a href="reg.php">还没有注册?点击注册</a>登录
<div>用户名:<input type="text" value="input your name" name="username"></div>
<div>密码:<input type="password" value="******" name="password"></div>
<div><input type="submit" value="登入"><input type="reset" value="重置"></div>
</div>
</form>
</body>
</html>
php表单

解决方案 »

  1.   

    echo "<script>location.href='login.php'</script>";
    浏览器中访问login.php跳转到本页面,又没加条件,当然会一直跳。
      

  2.   


    <html>
    <meta http-equiv="content" content="text/html;charset=utf8">
    <title>xxx</title>
    </head>
    <body>
    <?php    $Pusername=$_POST[username];
        $Ppassword=$_POST[password];    setcookie('cid',$Pusername);
        setcookie('cpassword',$Ppassword);      if($_COOKIE[cid] && $_COOKIE[cpassword])
        {
            echo "id and password cookie has set!"."<br />";
            echo "用户名:".$_COOKIE['cid']."密码:".$_COOKIE['cpassword']."<br />";
        }
    else{
    echo "<script>document.location.href='login.php'</script>";//改到这里来,当用户名与密码不存在的时候跳转到登录页login.php
    }
    ?>
    <form action="" method="POST">
    <div><a href="reg.php">还没有注册?点击注册</a>登录
    <div>用户名:<input type="text" value="input your name" name="username"></div>
    <div>密码:<input type="password" value="******" name="password"></div>
    <div><input type="submit" value="登入"><input type="reset" value="重置"></div>
    </div>
    </form>
    </body>
    </html>
      

  3.   

    你是想,有用户名和密码,就做判断,没有就让他输入?
    判断最好是在别的页面,不同的功能页面需要分开,比如login_process.php。
    然后login.php意外的页面,判断是否登陆成功,如果没有就跳到login.php
    login.php就不同再跳到自己页面了。
      

  4.   

    我认为应该是
    echo "<script>location.href='login.php'</script>";
      

  5.   

    你这个本身就是登录页面,为什么还要跳转到自己呢。你应该做的是,如果已经登录了,跳转到非登陆页面,比如 index.php逻辑问题~~~~