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!


    NEW! Download DB2 9.5 for Linux, Unix, and Windows

    Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! Harnessing the power of SQL and Java for high performance data access

    Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services.
    FREE! Go There Now!


    NEW! IBM Rational AppScan Standard Edition V7.7

    Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Integrating XML into Your Enterprise Using Data Federation

    XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats.
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! Software Change and Configuration Management Solution Guidelines

    This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management.
    FREE! Go There Now!


    NEW! The dirty dozen: preventing common application-level hack attacks

    As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
    FREE! Go There Now!


    NEW! Try IBM Rational Asset Manager V7.0 online!

    You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online.
    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-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek