LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP header("Location: xxx.php") not working? (https://www.linuxquestions.org/questions/programming-9/php-header-location-xxx-php-not-working-442742/)

baddah 05-08-2006 06:54 AM

PHP header("Location: xxx.php") not working?
 
Hi,I have the following code in a php script

header("Location: xxx.php");

where xxx is a another script in the same folder.for some reason,the browser does nothing when its suppose to redirect to the script.I'm using FireFox,is there any known bugs with FireFox and header function?I read somewhere to use ' ' instead of " ",but still it did nothing.This is really irritating me a bit,so any help will be appreciated.thanks

Spudley 05-08-2006 07:53 AM

Has your script output anything else prior to calling the header() command?

If you've output anything at all (even just the <html> tag), you can't call header(). Even if you think you haven't, one thing to check is that your script doesn't start with a blank line. Also, if you've got any includes, make sure they don't have any blank lines before or after the <? and ?> tags. That's caught me out before.

Finally, if you're not getting anything at all on the browser, have a look at your PHP config, and see whether it's supressing error messages. If you turn your error messages on, you might find it tells you something meaningful instead of just showing a blank page.

Hope that helps :)

baddah 05-08-2006 08:37 AM

o ok,i didn't know that.but i need to output some stuff,so i guess i'll have to use something <meta http-equiv="refresh" content="0; url=xxx.php>?I used to have this in my code but then some strange stuff happened,the browser kept refreshing as if it was in some endless loop,but anyway i'll try to use the <meta.. and get that working.thanks

krizzz 05-08-2006 05:16 PM

If you need to output something before redirection, simply use JavaScript to redirect :

<script>
window.location.href='blabla.html';
</script>

As Spudley wrote, header must be the very first thing of your script's output and even a single newline or space can screw it up.

baddah 05-09-2006 01:46 AM

thanks the javascript method worked,but i'd rather use meta tags.i've read somewhere that meta tags should also be used between the <head></head> tags,but i put the meta tags inside the <body> part and it seems to work.should this be fine?,to use the meta inside <body>?.my html skills not really very good,so sorry for all the questions.

krizzz 05-09-2006 09:50 AM

Meta tags are not supposed to be put insde of the body part. They belong to the head... Alhough it might worked for you from the body it's not gonna work in all the browsers and most likely will produce some errors. The proper way to do it is to use JS. I don't know why you don't want to use JS. Do you need a timeout? If so, then use setInterval function.

baddah 05-10-2006 01:51 AM

thanks,looks like its working fine.used JS rather.not to sure yet on how to delay the redirect yet,but I'm sure i'll figure it out.

krizzz 05-10-2006 09:00 AM

Sorry, I put the wrong function name there, it should be setTimeout not setInterval. setInterval calls the given function periodically.


All times are GMT -5. The time now is 07:39 PM.