If the user isn't on the abusive user list, and the
current page (stored in $_SERVER['PHP_SELF'])
isn't on a list of pages to exclude from abuse
checking, the count of pages that the user has looked at is
incremented. The list of pages to exclude is also defined in the
constructor. By calling check_abuse( ) at the top
of every page and putting pages that don't count as
potentially abusive in the $exclude array, you
ensure that an abusive user will see the error page even when
retrieving a page that doesn't count towards the
abuse threshold. This makes your site behave more consistently.
The next section of check_abuse( ) is responsible
for adding users to the abusive users list. If more than
$this->recalc_seconds have passed since the
last time it added users to the abusive users list, it looks at each
user's pageview count and if any are over
$this->pageview_threshold, they are added to
the abusive users list, and a message is put in the error log. The
code that sets $this->data['traffic_start'] if
it's not already set is executed only the very first
time check_abuse( ) is called. After adding any
new abusive users, check_abuse( ) resets the count
of users and pageviews and starts a new interval until the next time
the abusive users list is updated. After releasing its lock on the
shared memory segment, it returns false.
Figure 8-1. Abusive users
When it removes users from the abusive users list, instead of:
unset($abuse->data['abusive_users'][$_REQUEST['user']])
it sets the following to 0:
$abuse->data['abusive_users'][$_REQUEST['user']]
This still causes check_abuse( ) to return
false, but it allows the page to explicitly note
that the user was on the abusive users list but was removed. This is
helpful to know in case a user that was removed starts causing
trouble again.
When a user is added to the abusive users list, instead of recording
a pageview count, the script records the time the user was added.
This is helpful in tracking down who or why the user was manually
added to the list.