Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

PHP script for banning an ip I'm only 12 so please explain

OpenStudy (osanseviero):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

the other 3 are just dummy addresses anyway

OpenStudy (osanseviero):

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

OpenStudy (anonymous):

I thought banning '127.0.0.1' would basically ban your own machine.

OpenStudy (rsmith6559):

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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!