Forum Moderators: coopster

Message Too Old, No Replies

Redirect on IP

setup redirection based on Specific IP address

         

cyberdyne

6:14 pm on May 24, 2005 (gmt 0)

10+ Year Member



Hi all,
Ive been looking for a PHP script to redirect users with a specific IP address to a particular page within my site (possibly also, whilst disallowing them to view any other page and maybe using a MySQL db to record redirects).
My problem is, a couple of AOL users have been abusing the scoring system on my website games but they are accessig them via AOL's (IE-based) browser as opposed to IE6 or FF, which only returns the AOL Proxy IP instead of their real IP.
Now in order to ban these people, I am currently only able to ban the AOL Proxy IP, which means im actually banning a hell of a lot of users.
Therefor, id like to redirect AOL Browser users (195.*) to a page which will ask them to reconnect with a third party browser, thus returnig their real IP, just in case. :)
Any help appreciated.
Thanks
cyberdyne

dreamcatcher

6:29 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi cyberdyne, welcome to Webmaster World :)

If you know the IP addresses to ban, store them in an array, then check against the array and if the IP is found, redirect. If you want a wild card entry, ie all entries beginning with 195 you can use substr().

$ip = $_SERVER['REMOTE_ADDR'];

if (substr($ip,0,3)=="195")
{
//redirect
}

Array version:

$ipaddresses = array('123','234','345');

if (in_array($ip,$ipaddresses))
{
//redirect
}

Hope that helps

cyberdyne

6:37 pm on May 24, 2005 (gmt 0)

10+ Year Member



Thanks Dreamcatcher.

Im a bit of a novice at php, so can you elaborate on the //Redirect function please?
Whats the actual format i need to write the redirect page in please?

Is it somethng like:

<?php
$ip = $_SERVER['REMOTE_ADDR'];

if (substr($ip,0,3)=="195")
{
[mydomain.com...]
}
?>

Thank you again.

tima89

7:02 pm on May 25, 2005 (gmt 0)

10+ Year Member



If you need to redirect them right away, the fastest way is to use this:
header("Location: banner.php");
However, you may not output anything to the page before that function (e.g. you can't echo anything).
In case you really need to send some output to the user before hand, use javascript or meta refresh.