block ip range from viewing specific directory

  • defiled
  • Born
  • Born
  • defiled
  • Posts: 2

Post 3+ Months Ago

hello,

does anyone know of a free php script that will block and entire ip range or isp from viewing a certain folder/directory of my site, but not necessarily the entire site?

redirection would be good also.
i've searched the net and all i can find are pay programs.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Well, you could get better solution by putting the restriction in the web-server configuration.

Of course, it is possible that you can't do that.

I will tell you the solution from a conceptual point of view. Just because it is not easy to white the entire script.

a. You can get the remote IP address by using the hash value of key REMOTE_ADDR in the $_SERVER hash.
Code: [ Select ]
$_SERVER['REMOTE_ADDR']


b. You have to limit the range from a numeric point of view. As the value is a string, it will be easy for you to know about large providers with large IP ranges as the have the same starting numbers. In my country, all CableModem IP addresses start with 24.232 (24.232.0.0 to 24.232.255.255). But other providers don't have access to such big range. Then, they get ranges like 200.10.0.0 to 200.10.10.255
So, for such range you can't use string comparision. You have to convert the string into a 4 bytes number and the use logic operations for detecting IP inside the range.

c. Once you know certain IP is inside a black-listed range, you can use a header redirection:
Code: [ Select ]
header('Location: www.disney.com');
  • diverdan
  • Beginner
  • Beginner
  • diverdan
  • Posts: 46
  • Loc: Alabama, USA

Post 3+ Months Ago

disney is awesome
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

To compare the individual components of the array, use explode() on the IP
address to get the four octets into an array. Once you have them in an
array, compare them with the values you want to keep out and if they are
to be kicked out, redirect with _Leo_'s method. It is also advisable to put
exit() after the redirect..

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 85 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.