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 webmaster@xx.com and remember to include your IP Address <br><br>Your IP address is "; echo $_SERVER['REMOTE_ADDR']; exit(); } } ?> Quote Link to comment 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 Quote Link to comment 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"; } Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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(); } ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.