Log in

View Full Version : Redirect - PHP $location?



techno_race
04-03-2007, 02:45 PM
I know this may sound weird, but I need it.
I need to have a page:

http://yourdomain.com/yourfiles/loader.php?location=http://www.yahoo.com
where it shows "Fetching page" on the screen and then, after 5 seconds, loads Yahoo!.
Or, by changing the URL, Google.

thetestingsite
04-03-2007, 11:22 PM
Try this:



<?php

if (isset($_GET['location']) && $_GET['location'] != "") {

header('Refresh:5; url='.$_GET["location"]);
echo 'Fetching Page: '.$_GET["location"];

}

else {
//if url was not passed, then display form
?>

<form action="<?=$_SERVER['PHP_SELF'];?>" method="GET">
URL: <input type="text" name="location"> <input type="submit" value="Fetch URL">
</form>

<?php
}

?>


Hope this helps.

techno_race
04-03-2007, 11:35 PM
<?php

if (isset($_GET['location']) && $_GET['location'] != "") {

header('Refresh:5; url='.$location);
echo 'Fetching Page: '.$_GET["location"];

}

else {
//if url was not passed, then display form
?>

<form action="<?=$_SERVER['PHP_SELF'];?>" method="GET">
URL: <input type="text" name="location"> <input type="submit" value="Fetch URL">
</form>

<?php
}

?>
could work, but is it possible to display absolutely nothing if no URL? Would it just be:

<?php

if (isset($_GET['location']) && $_GET['location'] != "") {

header('Refresh:5; url='.$location);
echo 'Fetching Page: '.$_GET["location"];

}
?>

thetestingsite
04-03-2007, 11:39 PM
Would it just be:

<?php

if (isset($_GET['location']) && $_GET['location'] != "") {

header('Refresh:5; url='.$location);
echo 'Fetching Page: '.$_GET["location"];

}
?>

You got it. Just remember to call the script like so:



page.php?location=http://www.yahoo.com


(Remember the http:// or else it will not work properly).
Hope this helps.

techno_race
04-03-2007, 11:44 PM
My idea of not having else resulted in:

Warning: Cannot modify header information - headers already sent by (output started at /export/home/se/mydomain.com/public_html/fetch.php:3) in /export/home/se/mydomain.com/public_html/fetch.php on line 7
Fetching Page: http://www.yahoo.com
(mydomain.com is replacing my website address [se********.com]) Yes, I was using a PHP Web server.

thetestingsite
04-03-2007, 11:51 PM
Try this instead then:



<?php

if (isset($_GET['location']) && $_GET['location'] != "") {

header('Refresh:5; url='.$_GET["location"]);
echo 'Fetching Page: '.$_GET["location"];
}
?>


and if that doesn't work, instead of using header redirects use javascript or meta redirects instead.



<?php

if (isset($_GET['location']) && $_GET['location'] != "") {
echo '<html><head>
<meta http-equiv="Refresh" content="5;url='.$_GET["location"].'">
</head>
<body>
echo 'Fetching Page: '.$_GET["location"].'</body></html>';

}
?>


Hope this helps.