Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Redirect user by IP

Code Wizard, 12-30-2006



Script Note:
This script will redirect a visitor to the given url depending on their IP. In the example below, if the user has the IP of 207.32.63.152 they will be redirected to http://www.url.com. If they don't have this IP, they will get an error message. You must put this code before the rest of your HTML.

To the code!!!


<?
$ip = getenv("REMOTE_ADDR");
if ($ip !="207.32.63.152") {
echo "Sorry <b>$REMOTE_ADDR</b>, you can't be here!";
}
else {
header( "Location: http://www.url.com");
}
?>

P.S.
In the authorize users by IP script that I submitted there's an error. Here's how it should be. The error was a simple typo. The command getenv was misspelled. Below it is corrected.

<?
$ip = getenv("REMOTE_ADDR");
if ($ip !="127.0.0.1") {
echo "Sorry <b>$REMOTE_ADDR</b> You can't be here!";
}
else {
echo "You can be here!";
}
?>
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions