开发者

redirect to another page after logging in

I am working on how to redirect to another page by suing header() function, but it's not working, and give me an error message saying hat:Cannot modify header information - headers already sent by...... Anyone could help, thanks a lot. here is my php code

 if(isset($_POST['email'])){
    $email = $_POST['email'];
    $pass = $_POST['pass'];
     $query = "select email, password from member where email = '$email' and   password='$pass'";
     if(mysql_num_rows(queryMysql($query)) == 0)
{
   echo "Email/Password invalid&开发者_如何学JAVAlt;br/>";
}
else
{
    $query1 ="select uniid from member where email = '$email' and password ='$pass'";
     $result1 = queryMysql($query1);
      $row1 = mysql_fetch_object($result1);
      $uniid = $row1->uniid; 
       $_SESSION['uniid'] = $uniid;

       header("Location:View.php?view=$uniid");
   }
     }


THe headers must be sent before you write anything else. Put the header re-direct at the top of your code and it should work.


Consider starting your code with ob_start(). This turns off output buffering, which in short allows you to use header() and setcookie() anywhere at all.


You can't have any output (not even whitespace), before your call to header().

You can hunt down any opportunity for output, or you can start output buffering on the first line of your script. That will cause output to be buffered until either the end of the script, or an explicit call to ob_flush() (or similar functions). See ob_start()


A header must precede any output from the program. So, if you echo anything before the header modification, you will get that error. If you don't want to rearrange your code, you can use output buffering to delay other output until the header is sent.

See:
http://us2.php.net/manual/en/function.header.php
http://us2.php.net/manual/en/function.ob-start.php
http://us2.php.net/manual/en/function.ob-end-flush.php


The most common cause for this problem is that something somewhere is printing something to stdout before you send your header. You can either use ob_start as Kolink said, or you can turn on a global output buffer in php.ini, which will allow PHP to automagically send the header output first.


Make sure that there is no whitespace in your PHP file at all, in particular before the opening PHP tag. This counts as text output and it can't occur before sending headers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜