Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Requests originate from the following IP address range: -

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
This should probably be moved to Stack Overflow. – Martijn Heemels Nov 24 '11 at 22:40

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 = '';
$ipend = '';

echo ipbetweenrange('', $ipstart, $ipend); // true
echo ipbetweenrange('', $ipstart, $ipend); // true
echo ipbetweenrange('', $ipstart, $ipend); // true
echo ipbetweenrange('', $ipstart, $ipend); // false
share|improve this answer
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

Your Answer


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.