Reply to Re: redirection to another php page

Your name:

Reply:


Posted by J.O. Aho on 04/02/06 19:10

Stephen V wrote:
> I am afraid I don't understand.

If you use header(), you aren't allowed to make any output of any kind before
the header() is used

--- not working file 1 ---

<?PHP
header("Location: http://examplet.net");
?>
--- eof ---

--- not working file 2 ---
<?PHP
echo $_POST['data']."<br>\n";
header("Location: http://examplet.net");
?>
--- eof ---

file 1 has a white space in the beginning (a return before the '<?PHP'), this
will result in that the header() won't work as it has to be sent before any
output.

file 2 has an echo of a variable that may be sent to the page, as this is
output, it will prevent the header() to be sent as it should.


--- working file 3 ---
<?PHP
if(empty($_POST['data'])) {
header("Location: http://examplet.net");
exit;
}
echo "The $_POST data was: ".$_POST['data']."<br>\n";
?>
--- eof ---

file 3 has no output before the header() is used and the header() is in this
case in a if-statement which makes it not always to be used, if the variable
sent to the page isn't empty then an output is made but no header() sent.

Your original code had a none working header, should have looked like this:
header("Location: http://127.0.0.1/add_task.php?request_name=$req_name");

You can see my previous post, lines that are comments are unmodified rows of
your original code, rows that aren't comments are changes needed to make the
header() to work.


//Aho

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация