Jump to content


Photo

PHP Redirect to new website?


  • Please log in to reply
10 replies to this topic

#1 JustinMs66@hotmail.com

JustinMs66@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 138 posts

Posted 23 September 2006 - 12:18 AM

i know that this is how you redirect to a file on your website:
header("location: include/install.php");
but if i wanted to go to another website completely, how would i do that?

because when i try it like this:
header("location: http://www.google.com/");
it says:

Warning: Cannot modify header information - headers already sent by (output started at /www/locate1.php:9) in /www/locate1.php on line 10

and line 10 is that headers line that i made.

please help!??


#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 September 2006 - 12:36 AM

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...ic,95562.0.html

#3 JustinMs66@hotmail.com

JustinMs66@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 138 posts

Posted 23 September 2006 - 12:39 AM

no, there is no echo command or stuff. here is my EXACT 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>


#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 September 2006 - 12:41 AM

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...ic,95562.0.html

#5 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 23 September 2006 - 09:14 AM

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.

#6 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 23 September 2006 - 09:26 AM

Put
<?php ob_start(); ?>
at the very top and
<?php ob_end_flush(); ?>
at the very bottom.

#7 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 23 September 2006 - 02:39 PM

Or try...
header(sprint_f("location: URL"));

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

#8 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 23 September 2006 - 02:43 PM

In fact having
<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>
is stupid since the HTML will never be seen.

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

#9 pkSML

pkSML
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationBucyrus, Ohio

Posted 23 September 2006 - 03:21 PM

For redirections, you could show the user that they are being redirected.

Try this 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>

Of course, besides PHP, you can also do a meta-tag redirect or a javascript redirect.
-Stephen

Need a LitlURL?

Got code to share? --> The Code-Bin

#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 September 2006 - 03:24 PM

For redirections, you could show the user that they are being redirected.

Try this 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>

Of course, besides PHP, you can also do a meta-tag redirect or a javascript redirect.

WHats the point in that! The user isnt going to see anything. The user will be redirected straight away!

#11 pkSML

pkSML
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationBucyrus, Ohio

Posted 23 September 2006 - 03:44 PM

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.  :)
-Stephen

Need a LitlURL?

Got code to share? --> The Code-Bin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users