Add You
#1 in Business Subscribe Email Print

You are here: Home > Internet and Businesses Online > Web Development > Track Your Visitors, Using PHP

Tags

  • ipaddress
  • according
  • their
  • doesnt exist
  • fwrite httpwwwphpnetfwritethe
  • above example

  • Links

  • Sugarless Chocolate The Dieter's Best Friend
  • Is Your Radar Detector Up To Date With The Latest Frequencies?
  • California DUI Records
  • Add You - Track Your Visitors, Using PHP

    Marketing In Style - How Unique Is Your Web Site?
    In this article, I will share my opinions about the marketing web sites, how they look, how they are made, and how this affects your sales.Basically, I am surfing daily, and clicking on a lot of ads, I load a lot of web sites, and I check them out, from curiosity. This article goes out to all of those who imitate others, I know imitation is the greatest form of flattery but I think exaggerating this affects your sales, and also your reputation in the Internet Marketing World.A web site, is all you have, when you are an internet marketer, it is the thing you use to promote your products, and how that looks, or is made affects directly everything: your sales, your rankings, your traffic.I am writing this because, for example, 99% of the web sites I have loaded offering digital products look the same, and I
    y using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.

    Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:

    // Open log file

    $logfile = "/some/path/to/your/logfile.txt";

    if (file_exists($logfile)) {

    $handle = fopen($logfile, "r");

    $log = fread($handle, filesize($logfile));

    fclose($handle);

    } else {

    die ("The log file doesn't exist!");

    }

    Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:

    Seven Tips for Securing Your Organization's Network from Spam and Email Viruses
    Providing security against email related threats has become a burden for most IT professionals in 2006. According to a recent study by Postini, spam and email viruses now make up to 80% of all emails sent out as compared to 50% in 2000. As a result, IT professionals now face a tougher challenge in providing network security for this amount of spam. IT professionals also have the disadvantage of defending against new forms of email threats such as spam zombies, directory harvest attacks, mass mailing trojans, as well as the latest email virus.In this article, I have listed the seven most effective spam fighting tips for organizations with in-house mail servers. These seven tips are proven techniques I have used for my customers, partners and associates who wish to tighten their perimeter (network) security.1. F
    There are many different traffic analysis tools, ranging from simple counters to complete traffic analyzers. Although there are some free ones, most of them come with a price tag. Why not do it yourself? With PHP, you can easily create a log file within minutes. In this article I will show you how!

    Getting the information

    The most important part is getting the information from your visitor. Thankfully, this is extremely easy to do in PHP (or any other scripting language for that matter). PHP has a special global variable called $_SERVER which contains several environment variables, including information about your visitor. To get all the information you want, simply use the following code:

    // Getting the information

    $ipaddress = $_SERVER['REMOTE_ADDR'];

    $page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";

    $page .= iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", "");

    $referrer = $_SERVER['HTTP_REFERER'];

    $datetime = mktime();

    $useragent = $_SERVER['HTTP_USER_AGENT'];

    $remotehost = @getHostByAddr($ipaddress);

    As you can see the majority of information comes from the $_SERVER variable. The mktime() (http://nl2.php.net/mktime) and getHostByAddr() (http://nl2.php.net/manual/en/function.gethostbyaddr.php) functions are used to get additional information about the visitor.

    Note: I used a function in the above example called iif(). You can get this function at http://www.phpit.net/code/iif-function.

    Logging the information

    Now that you have all the information you need, it must be written to a log file so you can later look at it, and create useful graphs and charts. To do this you need a few simple PHP function, like fopen (http://www.php.net/fopen) and fwrite (http://www.php.net/fwrite).

    The below code will first create a complete line out of all the information. Then it will open the log file in "Append" mode, and if it doesn't exist yet, create it.

    If no errors have occurred, it will write the new logline to the log file, at the bottom, and finally close the log file again.

    // Create log line

    $logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . " ";

    // Write to log file:

    $logfile = '/some/path/to/your/logfile.txt';

    // Open the log file in "Append" mode

    if (!$handle = fopen($logfile, 'a+')) {

    die("Failed to open log file");

    }

    // Write $logline to our logfile.

    if (fwrite($handle, $logline) === FALSE) {

    die("Failed to write to log file");

    }

    fclose($handle);

    Now you've got a fully function logging module. To start tracking visitors on your website simply include the logging module into your pages with the include() function (http://www.php.net/include):

    include ('log.php');

    Okay, now I want to view my log file

    After a while you'll probably want to view your log file. You can easily do so by simply using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.

    Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:

    // Open log file

    $logfile = "/some/path/to/your/logfile.txt";

    if (file_exists($logfile)) {

    $handle = fopen($logfile, "r");

    $log = fread($handle, filesize($logfile));

    fclose($handle);

    } else {

    die ("The log file doesn't exist!");

    }

    Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:

    <
    Affiliate Website Tools That Every Business Needs to Succeed
    Affiliate tool #1 - A WebsiteNo matter what you've read online you need a website to succeed in affiliate business marketing.Not only does it give you a platform to sell from it helps create trust & confidence in your products with your visitors so that they click on the affiliate link.Don't believe the Siren calls that tell you that you can make an income from a blog with affiliate links or directly from adwords with affiliate links direct to the affiliate product.Visitors need convincing that the affiliate product is worth their hard earned cash.Your review, comparisons, appraisals and endorsements will be the deciding factor.Why else to you need an affiliate websiteTo offer other resources that draw visitors back to your website and therefore increase you
    ";

    $page .= iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", "");

    $referrer = $_SERVER['HTTP_REFERER'];

    $datetime = mktime();

    $useragent = $_SERVER['HTTP_USER_AGENT'];

    $remotehost = @getHostByAddr($ipaddress);

    As you can see the majority of information comes from the $_SERVER variable. The mktime() (http://nl2.php.net/mktime) and getHostByAddr() (http://nl2.php.net/manual/en/function.gethostbyaddr.php) functions are used to get additional information about the visitor.

    Note: I used a function in the above example called iif(). You can get this function at http://www.phpit.net/code/iif-function.

    Logging the information

    Now that you have all the information you need, it must be written to a log file so you can later look at it, and create useful graphs and charts. To do this you need a few simple PHP function, like fopen (http://www.php.net/fopen) and fwrite (http://www.php.net/fwrite).

    The below code will first create a complete line out of all the information. Then it will open the log file in "Append" mode, and if it doesn't exist yet, create it.

    If no errors have occurred, it will write the new logline to the log file, at the bottom, and finally close the log file again.

    // Create log line

    $logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . " ";

    // Write to log file:

    $logfile = '/some/path/to/your/logfile.txt';

    // Open the log file in "Append" mode

    if (!$handle = fopen($logfile, 'a+')) {

    die("Failed to open log file");

    }

    // Write $logline to our logfile.

    if (fwrite($handle, $logline) === FALSE) {

    die("Failed to write to log file");

    }

    fclose($handle);

    Now you've got a fully function logging module. To start tracking visitors on your website simply include the logging module into your pages with the include() function (http://www.php.net/include):

    include ('log.php');

    Okay, now I want to view my log file

    After a while you'll probably want to view your log file. You can easily do so by simply using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.

    Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:

    // Open log file

    $logfile = "/some/path/to/your/logfile.txt";

    if (file_exists($logfile)) {

    $handle = fopen($logfile, "r");

    $log = fread($handle, filesize($logfile));

    fclose($handle);

    } else {

    die ("The log file doesn't exist!");

    }

    Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:

    Simple Steps to a Great Banner Ad
    Everyone is using them now and if you’re planning on creating your own banner ad then there are some things that you should know.Standard SizeI’ll admit I made this mistake. I was too caught up in creating a really nice looking design that I made something that was not the standard size. Now it wasn’t much off the norm but when I found out I promptly changed the size. Keep to standards. I know that if your ad is slightly larger it may get more attention but if we all start doing this where will it stop? Creating an ad that is larger than standard is not the way to get attention. And in many places they will require you to keep to the industry standard.ContentThis must be short, simple, and very direct. You’ve really got to simplify this. I know that this is hard but there is not a lot of room on the
    function.

    Logging the information

    Now that you have all the information you need, it must be written to a log file so you can later look at it, and create useful graphs and charts. To do this you need a few simple PHP function, like fopen (http://www.php.net/fopen) and fwrite (http://www.php.net/fwrite).

    The below code will first create a complete line out of all the information. Then it will open the log file in "Append" mode, and if it doesn't exist yet, create it.

    If no errors have occurred, it will write the new logline to the log file, at the bottom, and finally close the log file again.

    // Create log line

    $logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . " ";

    // Write to log file:

    $logfile = '/some/path/to/your/logfile.txt';

    // Open the log file in "Append" mode

    if (!$handle = fopen($logfile, 'a+')) {

    die("Failed to open log file");

    }

    // Write $logline to our logfile.

    if (fwrite($handle, $logline) === FALSE) {

    die("Failed to write to log file");

    }

    fclose($handle);

    Now you've got a fully function logging module. To start tracking visitors on your website simply include the logging module into your pages with the include() function (http://www.php.net/include):

    include ('log.php');

    Okay, now I want to view my log file

    After a while you'll probably want to view your log file. You can easily do so by simply using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.

    Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:

    // Open log file

    $logfile = "/some/path/to/your/logfile.txt";

    if (file_exists($logfile)) {

    $handle = fopen($logfile, "r");

    $log = fread($handle, filesize($logfile));

    fclose($handle);

    } else {

    die ("The log file doesn't exist!");

    }

    Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:

    What You Have To Know To Become A Top Affiliate And Earn Money Online
    If you want to be a top affiliate there are important things that you should know before begin promoting an affiliate program. If you follow these recommendations you will save time and money on the steps to enrichment.1 The first and very important thing that you have to do is to create a memorable domain name for your website, since this will be essential to branding yourself on the Web.2 According to some experts you must also build a relationship by capturing email address for a free article or opt-in newsletter or maybe giving a free gift, the idea behind is to promote affiliate programs by emails.3 The third thing you have to do and is one of the best ways for promotion consists in writing articles for ezines and newsletters, like this one that you are reading, with your resource box at the bottom of
    otehost . '|' . $page . " ";

    // Write to log file:

    $logfile = '/some/path/to/your/logfile.txt';

    // Open the log file in "Append" mode

    if (!$handle = fopen($logfile, 'a+')) {

    die("Failed to open log file");

    }

    // Write $logline to our logfile.

    if (fwrite($handle, $logline) === FALSE) {

    die("Failed to write to log file");

    }

    fclose($handle);

    Now you've got a fully function logging module. To start tracking visitors on your website simply include the logging module into your pages with the include() function (http://www.php.net/include):

    include ('log.php');

    Okay, now I want to view my log file

    After a while you'll probably want to view your log file. You can easily do so by simply using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.

    Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:

    // Open log file

    $logfile = "/some/path/to/your/logfile.txt";

    if (file_exists($logfile)) {

    $handle = fopen($logfile, "r");

    $log = fread($handle, filesize($logfile));

    fclose($handle);

    } else {

    die ("The log file doesn't exist!");

    }

    Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:

    How To Get Link Popularity
    One of the important ways of getting traffic is to post to forums, search engines pick up and index forum posts very frequently, when posting be sure to add many keyword rich content and topics to each post. This will help provide popular keywords for your site. Good link popularity is important because it can increase the visitor traffic to your web page. Getting good quality incoming links back to your website is an excellent way of getting visitors that are targeted to your website. If you are selling niche products, you will need to get links from other sites that are related to the products or services you are selling.Building links to your website is not as difficult as everyone believes, you will need many hours dedicating your time to get the job done properly. Since Search Engine's are placing more and more em
    y using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.

    Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:

    // Open log file

    $logfile = "/some/path/to/your/logfile.txt";

    if (file_exists($logfile)) {

    $handle = fopen($logfile, "r");

    $log = fread($handle, filesize($logfile));

    fclose($handle);

    } else {

    die ("The log file doesn't exist!");

    }

    Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:

    // Seperate each logline

    $log = explode(" ", trim($log));

    After that it may be useful to get each part of each logline in a separate variable. This can be done by looping through each logline, and using explode again:

    // Seperate each part in each logline

    for ($i = 0; $i < count($log); $i++) {

    $log[$i] = trim($log[$i]);

    $log[$i] = explode('|', $log[$i]);

    }

    Now the complete log file has been parsed, and we're ready to start generating some interesting stuff.

    The first thing that is very easy to do is getting the number of pageviews. Simply use count() (http://www.phpit.net/count) on the $log array, and there you have it;

    echo count($log) . " people have visited this website.";

    You can also generate a complete overview of your log file, using a simple foreach loop and tables. For example:

    // Show a table of the logfile

    echo '';

    echo '

    ';

    echo '

    ';

    echo '

    ';

    echo '

    ';

    echo '

    ';

    foreach ($log as $logline) {

    echo '

    ';

    echo '

    ';

    echo '

    ';

    echo '

    ';

    echo '

    ';

    echo '

    ';

    echo '

    ';

    }

    echo '

    IP AddressReferrerDateUseragentRemote Host
    ' . $logline['0'] . '' . urldecode($logline['1']) . '' . date('d/m/Y', $logline['2']) . '' . $logline['3'] . '' . $logline['4'] . '
    ';

    You can also use custom functions to filter out search engines and crawlers. Or create graphs using PHP/SWF Charts (http://www.maani.us/charts/index.php). The possibilities are endless, and you can do all kinds of things!

    In Conclusion...

    In this article I have shown you have to create a logging module for your own PHP website, using nothing more than PHP and its built-in functions. To view the log file you need to parse it using PHP, and then display it in whatever way you like. It is up to you to create a kick-ass traffic analyzer.

    If you still prefer to use a pre-built traffic analyzer, have a look at http://www.hotscripts.com.

    HTTP = HTML link (for blogs, profiles,phorums):
    <a href="http://www.addyou.info/article/87620/addyou-Track-Your-Visitors-Using-PHP.html">Track Your Visitors, Using PHP</a>

    BB link (for phorums):
    [url=http://www.addyou.info/article/87620/addyou-Track-Your-Visitors-Using-PHP.html]Track Your Visitors, Using PHP[/url]

    Related Articles:

    Hooking Customers at the Bank Counter

    Two Money-Making Tips for Adsense Publishers

    Designing Your Website - The Top Ten Pages to Include

    Bookmark it: del.icio.us digg.com reddit.com netvouz.com google.com yahoo.com technorati.com furl.net bloglines.com socialdust.com ma.gnolia.com newsvine.com slashdot.org simpy.com shadows.com blinklist.com