|
Posted by Stephen V on 04/02/06 22:18
thanks alot for explaining so well.
"J.O. Aho" <user@example.net> a ιcrit dans le message de news:
49abb5Fnm14hU1@individual.net...
> 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]
|