Newbie - How to redirect to another URL?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

tonydm
Forum Newbie
Posts: 11
Joined: Fri Aug 06, 2004 1:07 pm

Post by tonydm »

Joe, that did the trick!
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

No problem! ;)
tonydm
Forum Newbie
Posts: 11
Joined: Fri Aug 06, 2004 1:07 pm

Post by tonydm »

Thanks Joe, Feyd, and ldomingues. Never got answer so quick on a forum. This is great!!!

tonydm

ps: still can't get it to work the other way. Stuff like this will drive me nuts. I'll still monkey with it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this is sorta the normal response time on the forums, if we understand the question... :D
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Well tonydm I can assure you that:

Code: Select all

<?php
if ($_GETї'id'] == "1")
{
header("location: http://forums.devnetwork.net");
}
else
{
print("Error!");
}
?>
Works perfect, are you positive that you have no code before this snippet or perhaps even any whitespace?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

this is sorta the normal response time on the forums, if we understand the question...
Very true indeed, hehe
tonydm
Forum Newbie
Posts: 11
Joined: Fri Aug 06, 2004 1:07 pm

Post by tonydm »

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<?php $p = $_GET['id']; ?>
<?php if ($p == "1")
{
print("<meta http-equiv=refresh content='0; url=http://forums.devnetwork.com'>");
}
?>
<body>
</body>
</html>
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Code: Select all

<?php
$p = $_GET&#1111;'id'];
if ($p == "1")
&#123;
 header("location: http://forums.devnetwork.net");
&#125; 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
Place it before html, thats why you are getting this error! Also tony, please make sure you have read the forum posting rules, hehe. (you should place your code in between the appropiate tags!)
tonydm
Forum Newbie
Posts: 11
Joined: Fri Aug 06, 2004 1:07 pm

Post by tonydm »

Every example of php script from php.net docs and other tutorial sites, as far as I have observed has the code in the body. That interesting.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yes tony, PHP can be anywhere, however when you are using headers, cookies etc you must place before any output...
Last edited by Joe on Fri Aug 06, 2004 1:46 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

as I said before, any text output before the header call is hit, you'd get that error.. so your code now should be fine, although Joe's should work fine too..

sidenote: please use

Code: Select all

tags when posting code.. thanks.
tonydm
Forum Newbie
Posts: 11
Joined: Fri Aug 06, 2004 1:07 pm

Post by tonydm »

"please use

Code: Select all

tags when posting code..."

forgive my brain freeze, but what should I have done diffently as edicate?  thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

tonydm
Forum Newbie
Posts: 11
Joined: Fri Aug 06, 2004 1:07 pm

Post by tonydm »

my appologies! I can see the advantage. Thanks for the grace period. Thanks all once again.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yes, these tags hold many advantages to us all. :D
Post Reply