LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
 
Search this Thread
Old 02-28-2014, 11:52 AM   #1
Habitual
Senior Member
 
Registered: Jan 2011
Location: Pelican Bay Correctional
Distribution: I can't wait for Linux to be 'underground' again.
Posts: 3,947
Blog Entries: 1

Rep: Reputation: Disabled
exclude <ip> from log_visitors.php


Hey:

I have a working php script to collect visitor stats. It works and is all "good".

How can I exclude an ip in/from this script?
PHP Code:
<?php
// from http://lawsonry.com/2013/12/wp-engine-hotfix-preventing-spam-and-bad-bot-traffic-part-ii/
// 02/18/2014 12 Noon
 
// Log Visitors
// This is a very basic way of logging users to a text file.
$remote_addr $_SERVER['REMOTE_ADDR'];
$details json_decode(file_get_contents("http://ipinfo.io/{$remote_addr}"));
$request_time date('Y-m-d g:i a'$_SERVER['REQUEST_TIME']);
$request_uri $_SERVER['REQUEST_URI'];
$user_agent $_SERVER['HTTP_USER_AGENT'];

$visitor "$request_time$remote_addr $details->country -> \"$request_uri\" as $user_agent\r\n";
 
// Record EVERY visitor in the visitors.txt file
file_put_contents("visitors.txt"$visitorFILE_APPEND);
 
?>
Thank you.

Found filter_input and this example. I'm no php coder, but I am examining the sample and searching for working snippets on the interwebs.

Last edited by Habitual; 02-28-2014 at 12:39 PM.
 
Old 02-28-2014, 03:17 PM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Location: Pelican Bay Correctional
Distribution: I can't wait for Linux to be 'underground' again.
Posts: 3,947
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
I'm leaning towards this:
PHP Code:
if (!$remote_addr == "xx.yy.zz.aa") {
file_put_contents("visitors.txt"$visitorFILE_APPEND);

Reference: http://www.freewebmasterhelp.com/tutorials/php/3

Thanks.

Last edited by Habitual; 02-28-2014 at 03:18 PM.
 
Old 03-01-2014, 04:31 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,168

Rep: Reputation: 258Reputation: 258Reputation: 258
Hi

Dont't think your code will work. Replace with this:

PHP Code:
if ($remote_addr != "xx.yy.zz.aa") { 
Another thing, this way of collecting the stats is not recommended for a busy site. For every hit, your server needs to do DNS lookups, contact ipinfo.io and wait for the result. It takes time, and if for example ipinfo.io doesn't respond, visitors at your site will get a long wait.

Your web server's log contains the information. It doesn't do IP address lookups or country lookup, because it's usually better to do it in batch when you create the stats. It doesn't matter much if the stats take a few minutes to generate. It matters more that visitors of your site gets the response fast.

http://en.wikipedia.org/wiki/List_of...ytics_software
 
1 members found this post helpful.
Old 03-01-2014, 06:44 AM   #4
Habitual
Senior Member
 
Registered: Jan 2011
Location: Pelican Bay Correctional
Distribution: I can't wait for Linux to be 'underground' again.
Posts: 3,947
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Guttorm:

It's me and the my insignificant technical blog. Visitors are at a minimum, if any.

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Find with an exclude/exclude file metallica1973 Linux - General 8 11-06-2011 09:39 PM
Can we use exclude option in"rm" command to exclude some files/folders? yadav_rk727 Linux - Newbie 1 02-03-2010 10:14 AM
CVS Exclude : Exclude sub directories from check out On Linux from command line shajay12 Linux - Newbie 1 08-03-2009 12:36 AM
PHP: List files in directory, exclude backups kenneho Programming 2 12-30-2005 04:27 AM


All times are GMT -5. The time now is 05:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration