Array problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gustaf Liljegren

    Array problem

    Hi all. I'm making a counter for my webpage, and I thought it would be
    neat if it wouldn't count my own page requests. So I wrote this code below:

    // Don't count requests from these addresses ('*' is permitted)
    $exclude_ip = array(
    '213.114.222.21 5',
    '213.114.222.21 6',
    '123.123.123.*'
    );

    // Get user IP
    $user_ip = getenv("REMOTE_ ADDR");

    // Make a flag
    $exclude_user = 0;

    // For each IP in the array
    foreach($exclud e_ip as $ip)
    {
    // If a wildcard is found
    if (strpos($ip, '*') > 0)
    {
    // Get position for wildcard
    $w_pos = strpos($ip, '*');

    // Shorten the compare strings to the wildcard position
    $ip = substr($ip, 0, $w_pos - 1);
    $user_ip = substr($user_ip , 0, $w_pos - 1);
    }

    // If an excluded IP is found
    if ($ip == $user_ip) $exclude_user = 1;
    break;
    }

    My current IP is 213.114.222.216 , but the flag $exclude_user is still 0.
    I hope someone can spot the error.

    Gustaf
  • deko

    #2
    Re: Array problem

    > Hi all. I'm making a counter for my webpage, and I thought it would be[color=blue]
    > neat if it wouldn't count my own page requests. So I wrote this code[/color]
    below:

    I had the same idea and came up with a script that you might find
    interesting. You can download the complete code at
    http://www.clearpointsystems.com/software.php - look for "Viscount"


    Comment

    • Gustaf Liljegren

      #3
      Re: Array problem

      deko wrote:[color=blue][color=green]
      >>Hi all. I'm making a counter for my webpage, and I thought it would be
      >>neat if it wouldn't count my own page requests. So I wrote this code[/color]
      >
      > below:
      >
      > I had the same idea and came up with a script that you might find
      > interesting. You can download the complete code at
      > http://www.clearpointsystems.com/software.php - look for "Viscount"[/color]

      Thanks deko. I'll have a look at your code. I found the problem now. Had
      just worked on it for too long... :-)

      Gustaf

      Comment

      Working...