470,849 Members | 1,084 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

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.215',
'213.114.222.216',
'123.123.123.*'
);

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

// Make a flag
$exclude_user = 0;

// For each IP in the array
foreach($exclude_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
Jul 17 '05 #1
2 1556
> 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:

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"
Jul 17 '05 #2
deko wrote:
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:

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"


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

Gustaf
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Federico G. Babelis | last post: by
5 posts views Thread by ritchie | last post: by
8 posts views Thread by Gerald | last post: by
204 posts views Thread by Alexei A. Frounze | last post: by
8 posts views Thread by intrepid_dw | last post: by
104 posts views Thread by Leszek | last post: by
4 posts views Thread by assgar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.