JustinMs66@hotmail.com Posted September 23, 2006 Share Posted September 23, 2006 i know that this is how you redirect to a file on your website:[code]header("location: include/install.php");[/code]but if i wanted to go to another website completely, how would i do that?because when i try it like this:[code]header("location: http://www.google.com/");[/code]it says:[color=purple]Warning: Cannot modify header information - headers already sent by (output started at /www/locate1.php:9) in /www/locate1.php on line 10[/color]and line 10 is that headers line that i made.please help!?? Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/ Share on other sites More sharing options...
michaellunsford Posted September 23, 2006 Share Posted September 23, 2006 You either have a space or newline before your <?php -- or you're outputting something to the browser before the header command (using echo, or print_r, etc.)understanding "headers already sent"http://www.phpfreaks.com/forums/index.php/topic,95562.0.html Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97033 Share on other sites More sharing options...
JustinMs66@hotmail.com Posted September 23, 2006 Author Share Posted September 23, 2006 no, there is no echo command or stuff. here is my EXACT code:[code]<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?phpheader("location: http://www.google.com/");?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97034 Share on other sites More sharing options...
michaellunsford Posted September 23, 2006 Share Posted September 23, 2006 you're outputting data to the browser before the header command. the absolute first thing you have to have is <?php, not <html> or anything else.read the FAQ link for a better explanation.http://www.phpfreaks.com/forums/index.php/topic,95562.0.html Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97036 Share on other sites More sharing options...
Prismatic Posted September 23, 2006 Share Posted September 23, 2006 Dont even worry about putting the HTML there, you're redirect page doesn't need to have any HTML in it if all your doing is redirecting. Strip out all the HTML and you will be good to go. Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97176 Share on other sites More sharing options...
Daniel0 Posted September 23, 2006 Share Posted September 23, 2006 Put [code]<?php ob_start(); ?>[/code] at the very top and [code]<?php ob_end_flush(); ?>[/code] at the very bottom. Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97184 Share on other sites More sharing options...
xyn Posted September 23, 2006 Share Posted September 23, 2006 Or try...header(sprint_f("location: URL"));I'm not 100% sure if thats the term but it's along those lines. Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97244 Share on other sites More sharing options...
Daniel0 Posted September 23, 2006 Share Posted September 23, 2006 In fact having [code]<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?phpheader("location: http://www.google.com/");?></body></html>[/code] is stupid since the HTML will never be seen.[code]<?phpheader("location: http://www.google.com/");?>[/code] would be enough. Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97249 Share on other sites More sharing options...
pkSML Posted September 23, 2006 Share Posted September 23, 2006 For redirections, you could show the user that they are being redirected.Try this code:[code]<?phpheader("Location: http://www.google.com/");?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Redirection ...</title></head><body>You are being redirected to <a href="http://www.google.com">Google</a>.</body></html>[/code]Of course, besides PHP, you can also do a meta-tag redirect or a javascript redirect. Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97266 Share on other sites More sharing options...
wildteen88 Posted September 23, 2006 Share Posted September 23, 2006 [quote author=pkSML link=topic=109142.msg439961#msg439961 date=1159024861]For redirections, you could show the user that they are being redirected.Try this code:[code]<?phpheader("Location: http://www.google.com/");?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Redirection ...</title></head><body>You are being redirected to <a href="http://www.google.com">Google</a>.</body></html>[/code]Of course, besides PHP, you can also do a meta-tag redirect or a javascript redirect.[/quote]WHats the point in that! The user isnt going to see anything. The user will be redirected straight away! Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97268 Share on other sites More sharing options...
pkSML Posted September 23, 2006 Share Posted September 23, 2006 They will only see the HTML for a small period of time (the time it takes for a DNS query for www.google.com to be completed, the request to be made to Google, and information from Google to be sent to the browser and displayed).All in all, they will see the page for a split-second, unless something goes wrong on the client's end. Then they know what is supposed to be happening.Anyways, this is Justin's decision. Just giving more options. :) Quote Link to comment https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/#findComment-97276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.