nuwandias Posted September 14, 2007 Share Posted September 14, 2007 Hi Guys.. I have a form, which submits to itself and checks for a condition and gives an error message if the condition is false and redirects the user to a new page if the condition is met. My problem here is redirecting the user to another page. when ever i call the header() function in a page which has html tags included, it gives a warning as shown below.Warning: Cannot modify header information - headers already sent by (output started at F:\xampp\htdocs\Login_Module\register.php:14) in F:\xampp\htdocs\Login_Module\register.php on line 3my code is as follows [indent]if(mysql_num_rows($result) >= 1){ echo "<tr><td colspan=\"2\" align=\"center\" valign=\"middle\"><font color=\"red\"><b>ERROR : </b></font></tr>"; } else{ mysql_close($con); goto(); }[/indent] the goto function is shown below. The php script which includes the goto function is located right above the <html> tag in the file function goto(){ header('Location : login.php'); } Is there anything wrong i'm doing here? If there is anyone who can help me out to get this redirection done, please be kind enough to reply soon.Thanks in advance,Nuwan. Link to comment Share on other sites More sharing options...
Synook Posted September 14, 2007 Share Posted September 14, 2007 All header() calls have to be completed before any text is sent to the client.This won't work <html><?php header("location:somewhere.php"); ?> But this will <?php header("location:somewhere.php"); ?><html> Just put that bit of code at the very top of the page. Link to comment Share on other sites More sharing options...
thibo1025 Posted September 14, 2007 Share Posted September 14, 2007 there are other ways to define ways to change your pages: either you put the php code at the top of your page, eitheryou can use the meta or the javascript technique Link to comment Share on other sites More sharing options...
jhecht Posted September 14, 2007 Share Posted September 14, 2007 or ob_start() works as well. putting that should allow for the output-buffering variable in the PHP system to be set which would allow you to redirect regardless of page output or not. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 17, 2007 Share Posted September 17, 2007 But even so, you would need to use output buffering at the start also. Whatever you do, it needs to be done before any output gets sent. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.