header() function to send an HTTP
Contrary to what some think,
die() has nothing to do with redirection. Use it only if you want to redirect instead of normal execution.
<?php header('Location: static.html'); $fh = fopen('/tmp/track.txt', 'a'); fwrite($fh, $_SERVER['REMOTE_ADDR'] . ' ' . date('c') . "\n"); fclose($fh); ?>
Result of three executions:
[email protected]:~> cat /tmp/track.txt 127.0.0.1 2009-04-21T09:50:02+02:00 127.0.0.1 2009-04-21T09:50:05+02:00 127.0.0.1 2009-04-21T09:50:08+02:00
Resuming — obligatory
exit() is some urban legend that has nothing to do with actual PHP. It has nothing to do with client “respecting” the
Location: header. Sending a header does not stop PHP execution, regardless of the client used.
5 thoughts on “How do I make a redirect in PHP?”
I was suggested this blog by my cousin. I am not sure whether this post
is written by him as no one else know such detailed about my difficulty.
You’re incredible! Thanks!
Hi there, yup this article is really pleasant and I have learned lot of things from it concerning
This is a topic which is close to my heart… Thank you!
Where are your contact details though?
An impressive share! I have just forwarded this
onto a co-worker who was conducting a little homework on this.
And he actually ordered me breakfast simply because I
found it for him… lol. So allow me to reword this….
Thanks for the meal!! But yeah, thanx for spending time to talk
about this matter here on your internet site.
Hi there to every one, the contents present at this web page are in fact awesome for people
knowledge, well, keep up the nice work fellows.