Jump to content

Archived

This topic is now archived and is closed to further replies.

JustinMs66@hotmail.com

PHP Redirect to new website?

Recommended Posts

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!??

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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>
<?php
header("location: http://www.google.com/");
?>
</body>
</html>
[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Put [code]<?php ob_start(); ?>[/code] at the very top and [code]<?php ob_end_flush(); ?>[/code] at the very bottom.

Share this post


Link to post
Share on other sites
Or try...
header(sprint_f("location: URL"));

I'm not 100% sure if thats the term but it's along those lines.

Share this post


Link to post
Share on other sites
In fact having [code]<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
header("location: http://www.google.com/");
?>
</body>
</html>[/code] is stupid since the HTML will never be seen.

[code]<?php
header("location: http://www.google.com/");
?>[/code] would be enough.

Share this post


Link to post
Share on other sites
For redirections, you could show the user that they are being redirected.

Try this code:
[code]<?php
header("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.

Share this post


Link to post
Share on other sites
[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]<?php
header("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!

Share this post


Link to post
Share on other sites
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.  :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.