wintallo Posted December 25, 2006 Share Posted December 25, 2006 Hey,First, thanks for reading! Second, I'm looking for a PHP script that bans IP addresses that [u]don't[/u] have the first octet of 69. For example, the script would block the IP address 23.34.21.255, but it wouldn't block the ip address 69.93.147.82. I already know that to get the user's ip address you use the getenv("REMOTE_ADDR") command. I just don't know how to split the IP address up so the script can just test the first octet. Again, thanks for reading!Joel Link to comment https://forums.phpfreaks.com/topic/31830-general-ip-banning/ Share on other sites More sharing options...
Orio Posted December 25, 2006 Share Posted December 25, 2006 You can use the .htaccess file for that. I am not sure how to do it exactly, but I think you should put in the .htaccess[code]deny from allallow from 69.[/code]I am not sure about the above tho!Orio. Link to comment https://forums.phpfreaks.com/topic/31830-general-ip-banning/#findComment-147584 Share on other sites More sharing options...
wintallo Posted December 25, 2006 Author Share Posted December 25, 2006 Thanks for the reply, but I need a PHP script to do this.-Joel Link to comment https://forums.phpfreaks.com/topic/31830-general-ip-banning/#findComment-147586 Share on other sites More sharing options...
kenrbnsn Posted December 25, 2006 Share Posted December 25, 2006 Use the [url=http://www.php.net/explode]explode()[/url] function:[code]<?php$ip = '69.73.147.62';$octets = explode('.',$ip);echo 'The first octet is ' . $octets[0];?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/31830-general-ip-banning/#findComment-147589 Share on other sites More sharing options...
Orio Posted December 25, 2006 Share Posted December 25, 2006 [code]<?php//$ip contains the user ip$parts = explode(".", $ip);if($parts[0] != 69) die("Get lost, you're not a 69!");else{ //valid user}?>[/code]Orio.EDIT- ken is faster I guess ;) Link to comment https://forums.phpfreaks.com/topic/31830-general-ip-banning/#findComment-147590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.