繁体   English   中英

为什么我不能重定向到另一页

[英]why i cant redirect to another page

此代码有什么问题? 它可以正确创建会话,但不要重定向我,“标题”前没有“回声”。

if(isset($_POST['login'])){
        include('../maincore/connect-db.php');
        $username=$_POST['username'];
        $password=$_POST['password'];
        $result = mysql_query("SELECT * FROM supporter WHERE username='$username'")
        or die(mysql_error());
        $row = mysql_fetch_array($result);
        $pass=$row['password'];

        if($password==$pass && $password!=''){
            $_SESSION['username']=$username;
            $_SESSION['name']=$row['name'];
            $_SESSION['family']=$row['family'];
            $_SESSION['id']=$row['id'];
            $_SESSION['type']=$row['type'];
            header('location: works.php');
        }else{
            header('location: index.php');
        }
    }

如果这是您的真实代码,那么您不应该对密码使用sha1或某种不可逆的哈希吗? 就是想..

刚刚尝试了您的代码,我的工作一切正常..因此,您必须向我们提供有关错误日志的更多信息

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Response_message

文档标题应在文档内容之前发送。

PHP是实时执行的,当我请求一个页面时,该页面不会被评估并发送,因此当您编写文档时,文档开始发送文档,并且无法再向传输添加任何标头。

您的问题是,您无法在标题之前回显某些内容。

错误示例:

<?php
    session_start(); // Send the session id header.
    echo "This is a rawr text"; // Print something to the document
    header("location: index.php"); // And this line will throw a error cause you already writed in the document.
?>

另一个错误:

<?php
    session_start();
?>
<body>
Inside of body
</body>
<?php
    header("location: index.php"); // this will throw a error cause the text upside has been already sent.
?>

解决方案:将代码( header()函数)放入文档中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM