Link Farm Code
  Home arrow Link Farm Code arrow Simple Outgoing Links/Url Hit Counter
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
LINK FARM CODE

Simple Outgoing Links/Url Hit Counter
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2002-01-18

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    This will count your outgoing hits so you know where people are going from your site. This was created quickly to manage outgoing hits, perhaps it'll be of some use. I heavily commented it so hopefully all will understand its logic. It is a very simple script. It just tracks url and number of hits.

    By : philip

    A new version of this lives here :

    http://www.theprojects.org/scripts/linkTracker/

    <?php
    // : Filename : go.php
    // : Version 0.0.1d

    // Me : Philip Olson @ theprojects.org
    // : Do whatever you want, just don't take credit as your own.
    // : NO CREDIT REQUIRED. :-) This is simple, all should learn to
    // create such a script, which is why it is so commented :-)

    // Use : <a href="go.php?url=www.google.com">google</a>
    // : Will insert url name and hit count into database.
    // : Manages outgoing hit count.

    // Set : mysql table name hits and url. hits is integer about 8chars
    // and url is to hold at least the length of your longest linked
    // url, set to about or at least 80chars.
    // Ex : CREATE TABLE url_redirect (
    // url varchar(100) NOT NULL,
    // hits int(10) DEFAULT '1' NOT NULL,
    // PRIMARY KEY (url)
    // );
    //
    // TODO: Error checking does not exist and should / will in version .2
    // If you want a version .2 then email author and ask!

    /*-----------------------------------------------------------------
    BEGIN USER CONFIGURATIONS
    -----------------------------------------------------------------*/

    // If go.php is called directly, goes to default_url.

    $default_url = 'www.theprojects.org';

    // Your database settings. You should include these from a secure
    // location (out of your web root) but it's up to you :-)

    $db_host = 'localhost'; // usually localhost
    $db_name = '';
    $db_user = '';
    $db_pass = '';
    $db_table = ''; // table holding url and hits fields.

    // Debug TRUE or FALSE. If you're debuggin, set to TRUE

    $debug = FALSE;

    /*-----------------------------------------------------------------
    END USER CONFIGURATIONS
    ------------------------------------------------------------------*/

    // Db connect function
    function db_connect()
    {
    global $db_host,$db_name,$db_user,$db_pass,$db_table,$connected;
    global $err;

    $conn = mysql_connect($db_host, $db_user, $db_pass);

    if ($conn) {
    $db_link = mysql_select_db($db_name,$conn);
    if ($db_link) {
    $connected = TRUE;
    } else {
    $err .= '[Db not being selected]';
    }
    } else {
    $err .= '[Db not being connected]';
    }
    }

    // This connects to db. In future consider more 'useful' placement
    // for this function.
    db_connect();

    // If $url is not empty then process request
    if (!empty($url)) {

    // If connected to database then insert info into database otherwise
    // just redirect url.
    if ($connected) {
    $msg .= '[$connected is TRUE, database being query\'d]';

    // Select current hit count from db where field url equals url
    $r = mysql_query ("select hits from $db_table WHERE url='$url'");

    // Return the results from above query
    $hits = @mysql_result($r,0);

    // If not yet in database (0 hits) then insert new url, value=1 hit
    if ($hits == 0) {
    $q = "INSERT INTO $db_table (url,hits) VALUES('$url','1')";

    // Else use current hit count plus 1 as we just got a hit
    } else {
    $q = "UPDATE $db_table SET hits = $hits+1 WHERE url='$url'";
    }

    // And finally, put info into the database
    mysql_query($q);
    }

    // Else $url is empty so set as default $host
    } else {
    $url = "$default_url";
    }

    // If debug is TRUE then show debug information and do not redirect.
    if ($debug) {

    print '<li>$url is ' . $url;
    print '<li>$hits is ' . $hits;
    print '<li>$q is ' . $q;
    print '<li>db_connect is ' . print db_connect();

    // If $msg and $err are not empty then print them out.
    if (!empty($msg)) { print '<li>Messages are ' . $msg; }
    if (!empty($err)) { print '<li>Errors are ' . $err; }

    } else {

    // Do redirection. To be paranoid (for no good reason), clear
    // cache first.
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header ("Pragma: no-cache");
    header ("Cache-Control: no-cache, must-revalidate");
    header ("Location: http://$url");
    exit;
    }

    // Email me questions, will most likely answer them.
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Link Farm Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Manual Tester V7.0.1

    Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    LINK FARM CODE ARTICLES

    - FreshSoftware Banner Image Rotater
    - LinkMachine
    - Pagination
    - Ask and Receive version 2.0
    - MyLinks Version 1.1
    - Flexphplink Pro
    - Flexphplink
    - Please remove
    - Simple Outgoing Links/Url Hit Counter
    - PHP-LINKS





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek