Need Help With Re-Direction

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

Post Reply
gowni
Forum Newbie
Posts: 7
Joined: Sat Sep 20, 2003 7:14 am
Contact:

Need Help With Re-Direction

Post by gowni »

Hello Friends,

I am have trouble with redirection.
To a file i am passing a url as parameter. It is working fine for some urls but for some urls its not re-directing properly. It gives File not found error, but when i type the url in the browser it works properly.
<?
$filename="Location: ".urldecode($_GET{url});
header($filename);
?>

example of url :
?url=http://www.qksrv.net/click-1167113-1027 ... D%3D334656'

thanks
heydude517
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

I'm presuming that's a typo as you have 2 ?url= vars in there?
gowni
Forum Newbie
Posts: 7
Joined: Sat Sep 20, 2003 7:14 am
Contact:

Its as it is

Post by gowni »

Hi friend,

The url it self is like that.

test.php?url=http://www.qksrv.net/click-1167113-1027 ... D%3D334656

the actual url to redirect also contains a variable called url.

thanks for help
heydude517
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

I'm still not sure why you are redirecting to a site that redirects you..why not just redirect straight to http://www.softwarenirvana.net ?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Re: Need Help With Re-Direction

Post by m3mn0n »

Try something like this:

Code: Select all

<?php
// old
$filename="Location: ".urldecode($_GET{url});
header($filename);

// new
$location = $_GET['url'];
$location = urldecode($location);
header ("Location: $location");
?>
gowni
Forum Newbie
Posts: 7
Joined: Sat Sep 20, 2003 7:14 am
Contact:

Hi

Post by gowni »

Hi Friends,

I tried the above too, but its not working...

But when i write :

<?
$pieces=explode("=",$url);
$url1=$pieces[0]."=";
for($i=1;$i<count($pieces);$i++)
{
$url1.=urlencode($pieces[$i]);
if($i!=(count($pieces)-1))
{
$url1.=urlencode("=");
}
}
print "<script> window.location.href=\"$url1\"; </script>";
?>


Its working ...
But i want to konw why the Header("Location : $location "); didn't workout...

What was i missing ?? or something else went wrong?

Thanks
Post Reply