Re: [PHP] allowing access to php page by IP
> certain webpage and keep everyone else out. I have written code to figure > out what someone's IP is, but am not sure about how I should verify > whether the IP is in the range of 10.8.4.* or 10.8.5.*. Any suggestions? $ipArray = explode( '.', $ipAddress ); if(( $ipArray[0] == 10 ) && ( $ipArray[1] == 8 ) && (( $ipArray[2] >=4 ) && ( $ipArray[2] <=5 ))) { echo 'Access granted'; } else { echo 'Get lost, ya bum!'; } Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] allowing access to php page by IP
Hi, Wednesday, October 8, 2003, 12:23:16 AM, you wrote: AW> Hello, AW> I want to allow access to a php page but am not sure how I should verify AW> the IP once I get it. I want to allow 10.8.4.* and 10.8.5.* to access a AW> certain webpage and keep everyone else out. I have written code to figure AW> out what someone's IP is, but am not sure about how I should verify AW> whether the IP is in the range of 10.8.4.* or 10.8.5.*. Any suggestions? AW> I was thinking of either using a regex (but I dunno regex so I'd have to AW> learn it) to stip off the .* octect and then compare the rest of the IP AW> and see if its either 10.8.4 or 10.8.5, or create a for loop and loop AW> through 1-254 and cat it to the end of 10.8.4. and 10.8.5. and compare it AW> to the IP they are coming from. Any suggestions on how I should do it? AW> Here is the code I have to get the IP: AW> if (getenv("HTTP_CLIENT_IP")) AW> { AW> $ip = getenv("HTTP_CLIENT_IP"); AW> } AW> elseif (getenv("HTTP_X_FORWARDED_FOR")) AW> { AW> $ip = getenv("HTTP_X_FORWARDED_FOR"); AW> } AW> elseif (getenv("REMOTE_ADDR")) AW> { AW> $ip = getenv("REMOTE_ADDR"); AW> } AW> else $ip = "UNKNOWN"; AW> Thanks, AW> Adam Convert the ip numbers to integers and check if the incoming ip is within range. You can use ip2long(); -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] allowing access to php page by IP
Hello, I want to allow access to a php page but am not sure how I should verify the IP once I get it. I want to allow 10.8.4.* and 10.8.5.* to access a certain webpage and keep everyone else out. I have written code to figure out what someone's IP is, but am not sure about how I should verify whether the IP is in the range of 10.8.4.* or 10.8.5.*. Any suggestions? I was thinking of either using a regex (but I dunno regex so I'd have to learn it) to stip off the .* octect and then compare the rest of the IP and see if its either 10.8.4 or 10.8.5, or create a for loop and loop through 1-254 and cat it to the end of 10.8.4. and 10.8.5. and compare it to the IP they are coming from. Any suggestions on how I should do it? Here is the code I have to get the IP: if (getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); } elseif (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } elseif (getenv("REMOTE_ADDR")) { $ip = getenv("REMOTE_ADDR"); } else $ip = "UNKNOWN"; Thanks, Adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php