Jump to content

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!??
Link to comment
https://forums.phpfreaks.com/topic/21737-php-redirect-to-new-website/
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
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]
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
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.
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 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!
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.  :)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.