PHP不回应

时间:2014-06-16 15:26:07

标签: php echo

我使用自定义登录脚本遇到了这个问题;重定向工作正常,但它不响应警报,这是我的代码:

        if ($_POST['submit']) {

            sleep(6);

            $expire = time() + (24 * 60 * 60);
            $cookie = 'level of clearence';

            if ($passcode == ($level4||$level3||$level2||$level1)) {
                echo '<script>alert("Happy Hacking");</script>';
                //    setcookie($cookie, 'level4', $expire);

                header('Location: home.php');
            }
            else if ($passcode != ($level4||$level3||$level2||$level1)) {
                echo '<script>alert("Incorrect PassCode");</script>';
                header('Location: index.php');
            }

        }

1 个答案:

答案 0 :(得分:1)

在输出已发送后,您无法发出标题。

            echo '<script>alert("Incorrect PassCode");</script>';
            header('Location: index.php'); // This wont work after your echo

该代码无效。您可以将其更改为JavaScript重定向

           echo '<script>
                   alert("Incorrect PassCode");
                   location.href="index.php";
                 </script>';

根据PHP Manual

  

请记住,在发送任何实际输出之前,必须通过普通HTML标记,文件中的空行或PHP来调用header()。

相关问题