PDA

View Full Version : Would this script be hard?



Toefur
February 5th, 2003, 07:27
I want a script that can redirect visitors based on the URL or IP address that they came from.

What I want to do exactly is put a header like the following, in the top of my php web pages:

<?php
$redirect_url = "http://othersite.com";
include("/server/location/script.php");
?>

So I will place that at the very top of my (former html) php pages, and then all traffic (except the IP's and such I list) get's sent to the other site listed as the redirect URL, and the IP's and URL's I add to the script get to view the page as they normally would.

I'm only new at PHP, so I don't think I can do something like this.

Would it be hard to do? If I got someone to do it for me, they wouldn't charge too much?

CareBear
February 5th, 2003, 08:30
does your host allow/use .htaccess? if so, it's just adding a few lines with the 'rules' and redirect based on those

Toefur
February 5th, 2003, 09:35
Mmhmm, my host allows htaccess. I was thinking of doing it like that, but there was a place before where I was using .htaccess with some other guys help, and then we changed to using scripts... so I figured it must be better... so more options can be added in later on, for instance... like being able to turn the script on and off, stuff like that...

I think I might just use htaccess for now, but I'd still appreciate help on what I asked about on the script itself as well in case I want it soonish...

Cyber-Scripter
February 5th, 2003, 13:41
I think you might be able to use a simple code like this:


$ipgetter = $REMOTE_ADDR;
$redirect_url = "http://othersite.com";

if ($ipgetter != "127.0.0.1" && $ipgetter != "127.0.0.1" && $ipgetter != "127.0.0.1")
{
echo "<script language=\"Javascript\">";
echo "document.location.href = \"" . $redirect_url . "\"";
echo "</script>";
}


There is another way to do this without the use of Javascript with header(location: blah.com) , but I sorta forgot how they work. That is the only way I could think of that would keep others out without the use of a login system.

Salam
February 5th, 2003, 14:16
script.php :

<?php
$allowed = array("127.0.0.1", "127.0.0.2") ;
if(!in_array($REMOTE_ADDR, $allowed)) { header("Location: $redirect_url") ;
die() ; }
?>
And add this code in the top of your pages :
<?php
$redirect_url = "http://othersite.com";
include("/server/location/script.php");
?>