Header() don't work

From: Date: Mon, 15 Oct 2001 04:04:22 +0000
Subject: Header() don't work
Groups: php.general 
Request: Send a blank email to php-general+get-71057@lists.php.net to get a copy of this message
I don't think there are any html output sent out before the header() in the login.php, so the header() should redirect to other page.(of course, the login name and password are right.) But the IE shows error as below: Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\web\lib.inc:18) in c:\program files\apache group\apache\htdocs\web\login.php on line 18 The other question is can I put the session_start() after the line where the login is ok; But if I do so, error showed: Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\web\lib.inc:18) in c:\program files\apache group\apache\htdocs\web\6.php on line 16 In brief, what I need is redirection by header() and the generating of a session when after the login is ok. Thanks Mike -------------------------------------------------------------------------- (The scripts below are named as login.php which process the login form in the login.htm. ) login.php <? session_start(); if($submit!=""){ if($login_name!=""&&$login_password!=""){ $link=mysql_connect("localhost","",""); $link=mysql_select_db("db"); $query="select password, user_id from users where user_name='$login_name'"; $res=mysql_query($query); $num=mysql_num_rows($res); if($num==0) echo "The login name or password is not right!<br>"; if($num==1){ $arr=mysql_fetch_array($res); if(!strcmp($arr['password'], $login_password)){ /* ??? can I put the session_start(); here? For from here the login is ok, and the session is actually needed.*/ $user_id=$arr['user_id']; session_register("user_id"); header("location: page2.php"); /* Turn to page2.php automatically, but error showed here while running */ exit(); }else echo "The login name or password is not right!<br>"; } } } ?>

« previous php.general (#71057) next »