SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Logging clicks?

  1. #1
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've noticed on many sites external links are logged (so they know how many people clicked the link).

    Link would be something like

    http://domain.com/go.php?id=123

    My guess on how this works is (in pseudo code):

    <?php
    SELECT url at id=123
    UPDATE count at id=123
    header ("location:url")
    ?>

    I'm new at this and want to make sure this is the most effecient method?

    Thanks for the help!

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just try something like this:
    PHP Code:
    <?php
    $query 
    mysql_query("select * from links WHERE id='$id'");
    $array mysql_fetch_array($query);
    mysql_query("UPDATE links SET clicks=clicks+1");
    header("Location: $array[url]");
    ?>
    Untested but it should work.

    Hope that helps

  3. #3
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks - the actual code I can figure out, I was just wondering if my methodology was correct.

  4. #4
    SitePoint Member
    Join Date
    Mar 2001
    Location
    Albany, NY
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another thing you might want to try is logging the $REMOTE_ADDR and comparing that before incrementing the clicks in the db. This way you'd be able to see your unique clicks.
    John Reyes
    HostRocket.com Support

  5. #5
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good idea, John. Thanks for the help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •