zhangy Posted January 21, 2009 Share Posted January 21, 2009 Hello, I am trying to disallow form submissions from being processed based upon the users ip address. As of now all forms are processed regardless of ip, Im just trying to figure out how to ad something like a $blockip variable that will basically stop the processing code from working if the ip address of the user matches said variable. Does anyone have an idea as to how I could perform this? Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/ Share on other sites More sharing options...
haku Posted January 21, 2009 Share Posted January 21, 2009 Store blocked IPs in the database. When a user posts, check to see if their IP is in the database. If it is, don't let them post. Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-741971 Share on other sites More sharing options...
zhangy Posted January 21, 2009 Author Share Posted January 21, 2009 If it can be done, id rather not store blocked ips in the database, but rather in an array. Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-741972 Share on other sites More sharing options...
haku Posted January 21, 2009 Share Posted January 21, 2009 Arrays are only valid during the running of the script. So when the script ends, the array disappears. Basically, you need to store the IP addresses somewhere. If you don't store them, then how will you know which ones to block? You can store it a few different ways: * in the database * in a file * hard code the IPs directly into the script you are using Whichever method you use, the testing is the same - see if the current IP is the same as one of the blocked IPs. Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-741974 Share on other sites More sharing options...
zhangy Posted January 21, 2009 Author Share Posted January 21, 2009 yes, i was thinking code it into the script... but dont know how ??? Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-742031 Share on other sites More sharing options...
haku Posted January 21, 2009 Share Posted January 21, 2009 $uip = // insert the user's IP address here $banned_ips = array('123.456.789.012', '1.1.1.1', '192.168.0.666'); // add as many ips as necessary if(in_array($uip, $banned_ips)) { die("banned user"); } Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-742169 Share on other sites More sharing options...
zhangy Posted January 22, 2009 Author Share Posted January 22, 2009 In this case should $uip = $_SERVER['REMOTE_ADDR'];? or $uip = array('123.456.789.012', '1.1.1.1', '192.168.0.666');? Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-742873 Share on other sites More sharing options...
haku Posted January 22, 2009 Share Posted January 22, 2009 $_SERVER['REMOTE_ADDR'] But that won't catch all IPs. Spend some time with google and find out how to get a user's IP. There are some more comprehensive scripts out there. Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-742907 Share on other sites More sharing options...
zhangy Posted January 22, 2009 Author Share Posted January 22, 2009 Appreciate the help haku, thanks. Link to comment https://forums.phpfreaks.com/topic/141730-solved-separate-the-good-from-the-bad/#findComment-743018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.