dezkit Posted March 26, 2008 Share Posted March 26, 2008 is there a way so that if the ip is 12.123.123.12 that it states a reason <?php $banned_ip = array(); $banned_ip[] = '12.123.123.12'; $banned_ip[] = ''; $banned_ip[] = ''; foreach($banned_ip as $banned) { $ip = $_SERVER['REMOTE_ADDR']; if($ip == $banned){ echo "<br><br><br><br><br><br><br><br><center> <font size='+2'>You have been banned from this site for ??????.</font> <br>For further information about your ban, please email us at [email protected] and remember to include your IP Address <br><br>Your IP address is "; echo $_SERVER['REMOTE_ADDR']; exit(); } } ?> Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/ Share on other sites More sharing options...
cooldude832 Posted March 26, 2008 Share Posted March 26, 2008 you can't ban by IP because the IP is not a valid resource to identify a single user. You can only "allow" by IP if you know of a static source you wish to allow Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501721 Share on other sites More sharing options...
dezkit Posted March 26, 2008 Author Share Posted March 26, 2008 wait so i cant do something like this? if ($banned_ip[]=="12.123.123.12") { echo "Spamming"; } Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501723 Share on other sites More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 Cooldude isn't saying the code isn't possible, he's saying that it's not the best way to do it because it can be easily bypassed. Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501724 Share on other sites More sharing options...
dezkit Posted March 26, 2008 Author Share Posted March 26, 2008 ohh, im a beginner anyways... so i dont care if it can be bypassed can any of you create a code lol Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501726 Share on other sites More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 What does the code you have do? Just glancing over it quick it looks accurate. Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501728 Share on other sites More sharing options...
dezkit Posted March 26, 2008 Author Share Posted March 26, 2008 i dont think you guys get what im saying i am saying that if the person on the computer has a ip banned from the site, so it echo's a reason why he was banned like if($ip == $banned){ echo "spamming"; exit(); } } or something Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501730 Share on other sites More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 We get what you're saying, what I'm asking is what's wrong with the way you were doing it. Create either a db table of banned ip addresses, or an array in a php page. Check if the current ip address is either in that db table or in the array, if it is display an error. Where are you confused? Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501735 Share on other sites More sharing options...
dezkit Posted March 26, 2008 Author Share Posted March 26, 2008 kk i choose the php array, now what do i do. lol Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501738 Share on other sites More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 Try this: <?php // Array of ip addresses $blocked = array("12.123.123.12","1.1.1.1"); // keep adding ip addresses by comma. 1.1.1.1 is an example, feel free to remove it // Grab users ip address $ip = $_SERVER['REMOTE_ADDR']; // Check if ip is supposed to be blocked if(in_array($ip,$blocked)){ echo "Spam"; die(); } ?> Something like that should work Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501742 Share on other sites More sharing options...
dezkit Posted March 26, 2008 Author Share Posted March 26, 2008 thanks for the code, but one problem... i want different reasons for different ips Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501746 Share on other sites More sharing options...
dezkit Posted March 26, 2008 Author Share Posted March 26, 2008 nevermind, i got it thanks alot! <?php $spam = array("xxxxx","xxxxx"); $other = array("xxxxx","xxxxx"); $ip = $_SERVER['REMOTE_ADDR']; if(in_array($ip,$spam)){ echo "Spam"; die(); } if(in_array($ip,$other)){ echo "Other"; die(); } ?> Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501748 Share on other sites More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 Yeup that's one way to do it. Glad I could help Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501756 Share on other sites More sharing options...
cooldude832 Posted March 26, 2008 Share Posted March 26, 2008 Cooldude isn't saying the code isn't possible, he's saying that it's not the best way to do it because it can be easily bypassed. No I'm saying innocent people will get banned in your system Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501761 Share on other sites More sharing options...
p2grace Posted March 26, 2008 Share Posted March 26, 2008 You mean because of isp dynamic ip releases? Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501763 Share on other sites More sharing options...
cooldude832 Posted March 27, 2008 Share Posted March 27, 2008 You mean because of isp dynamic ip releases? yes Link to comment https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501793 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.