I have a php/mysql hit counter script wich works ok. Below is the part where i exclude my own ip adress. I dont have sstatic ip, so I have to change this from time to time.

How do I exclude a range of ip adresses like for example all between
84.202.66.0 and 84.202.66.255 ?

Iv tried many different things but cant get it to work๐Ÿ™

# Exclude my own ip
if($ip != '84.202.66.8') {
 $sql_insert = "INSERT INTO $table (browser,ip,date_now,date_first)
 VALUES ('$browser','$ip','$date_now','$date_first')";
 $do_insert = mysql_query($sql_insert);
}

    If you're using PHP >= 5.1, then you could do:

    if(implode('.', explode('.', $ip, -1)) != '84.202.66') {

    Otherwise, you could do something like:

    $ip_subnet = explode('.', $ip);
    $my_subnet = array('84', '202', '66');
    
    if(!($ip_subnet[0] == $my_subnet[0] && $ip_subnet[1] == $my_subnet[1] && $ip_subnet[2] == $my_subnet[2])) {

      Glad I could help. Don't forget to mark this thread resolved (if it is)... or feel free to ask questions if you don't understand my code.

        Write a Reply...