heya!
For a long time I have many problems with function Header in PHP. This cause an error of outup buffering when we have something like this:
<?php
echo "Hi world!";
header ("location: main.php");
?>
this cause a error that i refer previous. The first solution for this was using javascript like this:
echo "<SCRIPT>window.location=\"main.php\"; </SCRIPT>";
but this isn’t very good because when user click back on browser isn’t possible, this function not permit Back.
Then I have to found another solution , finally :geek:
like this:
<?php
ob_start();
echo "Hi world!";
header ("location: main.php");
ob_end_flush();
?>
Using this functions (ob_start(); and ob_end_flush(); ), we can have many outputing to buffer without cause error
You can found more information about this functions in
www.php.net
I test this in PHP 4.0.6 and 4.3.1
I hope this help someone :azn:
xauz!
system
August 6, 2003, 1:58pm
2
well if you are going to do that, then why not just take the output code (echo) out. The ob_start disallows output being displayed… so that entire code could be shortened to
<?
header("Location: whereever.php");
?>
system
August 6, 2003, 2:25pm
3
system
August 6, 2003, 3:22pm
4
Jubba can be but if you need to have something like this
<?php
if ($status == "loginok") {
echo "Validation Ok!"
}else {
header ("location: main.php");
}
?>
you can’t have only header (“location: main.php”);
(-:
system
August 6, 2003, 3:30pm
5
look at your code again. That would work without using the ob_start/ob_flush because of the if statement. If its not true then there is no output and the header gets parsed… if the statement is true… the output is run and the header doesn’t get parsed…
system
August 6, 2003, 3:44pm
6
No… don’t works … the logical is that work but not …
As i was sad, i test in versions 4.0.6 and 4.3.1 …
system
August 6, 2003, 3:49pm
7
works fine on: 4.3.2
must be the older versions… but I never had trouble with this before I upgraded my server…
eh whatever…
system
August 6, 2003, 4:14pm
8
Doesn’t PHP have HTTP Headers like ASP?
system
August 6, 2003, 4:19pm
9