![]() |
header(location) does not work?
This doesnt work:
PHP Code:
Warning: Cannot modify header information - headers already sent by (output started |
With header(), you can't have any output or whitespace outputted to the browser before that function is called. If that's the entire code for the page, try getting rid of the blank lines. If it still doesn't work, put the <? and ?> on the same line as the function.
|
This file is included in another file.
|
Then what should I do? I want the script to do like this line.
EDIT: Maybe I could use some JavaScript to send the user to the page? |
Then you must send that header before any actual output. If you can't do that, use another redirection method (like a meta tag - which will invalidate your html - or a javascript code).
|
What would this function look like in Javascript? With all the output. I'm not the best one to JavaScript
|
Just do this:
PHP Code:
|
Well it doesnt quite work. How should I get the URL in?
|
Dont use javascript, too many people have it disabled. Use this code
Code:
<META HTTP-EQUIV="Refresh" |
What is being output / sent to the browser before the redirect header? If you are doing an instant redirect do you really need to output something first since I'm guessing no-one would see it?
Alan |
Quote:
Javascript redirection method: Code:
function do_redirect( url )PHP Code:
|
Quote:
|
Hello, that's why I included the exit; command so if for some odd reason JS is disabled then it just exits, stops. xenon's method works but so does mine. As for the putting in the URL...
PHP Code:
|
You shouldnt stop execution because they disabled javascript, the site has to work fully for them.
|
OK, then put in an echo with a link before the exit; command. Just keep in mind that the META method can be disabled too.
|
Rather than working around the problem (ie, finding a new way to redirect) why not solve the initial problem and be done with it? Sending out headers should never, ever, come after any content has been sent out. Re-structure your PHP code so that the redirect can happen before anything is outputted and bam, no need to bother with resorting to HTML/JavaScript/ask-them-politely redirects.
Also -- a minor point in the grand scheme of things -- is that the value in the Location header should be a full URL: http://domain.com and all the rest. It will work with just index.php... but just because something works, doesn't make it right. :-) |
Quote:
|
I sometimes go without JavaScript because I disable it to test sites that use it (to see if they work without it), and forget I turned it off.
|
Quote:
|
| All times are GMT. The time now is 08:44 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0