Redirect after execution
-
I've tried putting
header('Location: http://www.google.com/');
at the end of one of my scripts, but it won't redirect. If It's just
< ?php
header('Location: http://www.google.com/');
?>it works fine. I need to be able to run some stuff before it redirects the page.
-
I've tried putting
header('Location: http://www.google.com/');
at the end of one of my scripts, but it won't redirect. If It's just
< ?php
header('Location: http://www.google.com/');
?>it works fine. I need to be able to run some stuff before it redirects the page.
In the PHP documentation[^] it actually quotes:
php.net wrote:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Two solutions:
- Have it (the header) at the top of the page before you output anything to the browser.
- Use Output Buffering[^] to hold the output before it is sent to the browser.
If at first you don't succeed, you're not Chuck Norris.
-
In the PHP documentation[^] it actually quotes:
php.net wrote:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Two solutions:
- Have it (the header) at the top of the page before you output anything to the browser.
- Use Output Buffering[^] to hold the output before it is sent to the browser.
If at first you don't succeed, you're not Chuck Norris.
-
I've tried putting
header('Location: http://www.google.com/');
at the end of one of my scripts, but it won't redirect. If It's just
< ?php
header('Location: http://www.google.com/');
?>it works fine. I need to be able to run some stuff before it redirects the page.
You can run stuffs before that but make sure you dont echo anything else before giving this redirect. For e.g. validation of usernames, or anything which should be done before any HTML tags or echo is done.. - Jay.