header('Location:http://www.php.net'); $f = fopen('demo.txt','w+'); fwrite($f,'Test'); fclose($f); ?>If you run this code your browser will be display the php.net site. However don't forget that the code after the header function will be executed! So to save resources you should call a die() function after the redirection as you can see below:
Code:
header('Location:http://www.php.net');
die();
$f = fopen('demo.txt','w+');
fwrite($f,'Test');
fclose($f);
?>
The only thing you have to do is to change the URL inside the header parameter. However if you write the echo before the redirection you will get an error like this: Warning: Cannot modify header information - headers already sent by To avoid this problem you can use PHP output buffering as follows:
Code:
ob_start()
echo "Test"
header("Location: http://www.php.net");
ob_flush();
?>
0 komentar:
Post a Comment