www.webdeveloper.com
Results 1 to 2 of 2

Thread: Log Amount of Clicks

  1. #1
    Join Date
    Nov 2007
    Posts
    362

    Log Amount of Clicks

    Every time a link is clicked, how do I keep a record of the number of clicks a link has received, and store the results in a database?

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,736
    Just write a clickthru script:
    PHP Code:
    if((!empty($_GET['url'])) and (preg_match('/^(?:f|ht)tps?:\/\/[^\/]+\.[^\/]+(\/[^\'"]*|)$/i'$_GET['url'])))
    {
        
    /*
          Connect to DB here
        */
        
    $url mysql_real_escape_string(preg_replace('/^http:\/\/(www\.)?([^\/]+).*$/i''\2'$_GET['url']));
        
    $query "INSERT INTO `$tablename` (`url`, `clicks`) VALUES ('$url', 1) \n".
                 
    "ON DUPLICATE KEY UPDATE `clicks` = `clicks` + 1";
        
    mysql_query($query)
        
    header('Location: '.$_GET['url']);

    Last edited by bokeh; 11-15-2007 at 10:21 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles