PHP script for banning an ip I'm only 12 so please explain
first of all, you should know that ip changes really often: each time modem is reseted. <?php $deny = array("111.111.111", "222.222.222", "333.333.333"); if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) { header("location: http://www.google.com/ "); exit(); } ?> http://perishablepress.com/press/2007/07/03/how-to-block-ip-addresses-with-php/ explanation
cut out "111.111.111", "222.222.222", "333.333.333" from that array, and add in "127.0.0.1". Most common IP address
the other 3 are just dummy addresses anyway
yeah they were just example. And no, you dont want to ban the most commom IP address because that will make a high percentage of people getting banned
I thought banning '127.0.0.1' would basically ban your own machine.
It would. 127.0.0.1 is localhost. It's the way that a computer talks to itself via network protocols. What this code is doing is declaring an array ( a collection ) of IP addresses ( as strings, that's what the double quotes are for ) separated by commas named deny. in_array is a function that checks if what it's given is first is in the array that it's given second. "REMOTE_ADDR" is an environmental variable that's available to programs called by the webserver. If $REMOTE_ADDR is in the array named deny, then the code instructs the webserver to redirect the user to Google.
Join our real-time social learning platform and learn together with your friends!