Jump to content

Calling header() function within html code


nuwandias

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...