Forum Moderators: phranque
I know how to restrict users by IP using good old .htaccess and shoot them to a 403 page no problem. What I want to do is to take a certain block of IP's and shoot them to a custom 403 page with some info based on where they are coming from.
For instance, if the ip block of 100.205.*.* belonged to Noname University, I would want all users coming to my site via that ip block to be sent to an error page saying:
"I am sorry, visitors to this site from NoName University have been blocked"
My knowledge in fancy PHP, Perl, CGI, etc is limited to hacking together mostly complete scripts...so the simpler the solution the better....
Big Thanks!
For example in Perl, you could use:
print <beginning_of_doc>;
if($ENV{'IP_ADDRESS} =~ /^100.205./)
{
print "No Name uni have been blocked";
}
else
{
print "You are not permitted to view this page";
}
print <end_of_doc>;
Or alternatively you could redirect:
if($ENV{'IP_ADDRESS'} =~ /^100.205./)
{
print "Location: nonameuniversity.html\n\n";
}
else
{
print "Location: 403.html\n\n";
}
Notes: $ENV{'IP_ADDRESS'} is made up, you'll need to look up what IP_ADDRESS actually is. The '.' is the regular expression actually matches anything, they should really be procedded with a '\', but they'll match the dot anyway. Both are pseudo-code and can be transported to php, asp, perl, c++ etc...