Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am setting up trialpay for my website. The website shows :

Requests originate from the following IP address range: 70.42.249.1 - 70.42.249.255

In PHP, how do I check to see if the bot/person visiting my auth page falls within the above IP range?

share|improve this question
1  
This should probably be moved to Stack Overflow. –  Martijn Heemels Nov 24 '11 at 22:40
add comment

2 Answers

foreach( range( 1, 255 ) as $number )
{

    if( $userIp == '70.42.249.' . $number )
        // we have a match, do whatever you want

}

Something along those lines. And yes, this should probably be moved to Stackoverflow.

share|improve this answer
add comment

Since you are dealing with ip addresses, it's probably easier to treat them as integers instead of strings. You can use the ip2long() function to do this.

Here's a working function to help you out:

function ipbetweenrange($needle, $start, $end) {
  if((ip2long($needle) >= ip2long($start)) && (ip2long($needle) <= ip2long($end))) {
    return true;
  }
  return false;
}

$ipstart = '70.42.249.1';
$ipend = '70.42.249.255';

echo ipbetweenrange('70.42.249.1', $ipstart, $ipend); // true
echo ipbetweenrange('70.42.249.255', $ipstart, $ipend); // true
echo ipbetweenrange('70.42.249.128', $ipstart, $ipend); // true
echo ipbetweenrange('192.168.0.1', $ipstart, $ipend); // false
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.