Is there any way to find out how many times an outbound link has been clicked?

Discussion in 'HTML & Website Design' started by Sullmoney, Aug 27, 2006.

  1. #1
    Imagine there is site A and site B. You own site A. Site B is a related site, but you do not own it.

    Site A has a link for site B on the sidebar.

    Is there a way to find out how many times the link for site B has been clicked?

    Thank you very much.
     
    Sullmoney, Aug 27, 2006 IP
  2. sojic

    sojic Active Member

    Messages:
    133
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Yes, it is possible.

    For that you need PHP script. I do not know do you have links in database or you will store results in text file, or some another way, but the code will be something like this (I do not have PHP at the moment, so I can not test it):

    Filename: counter.php
    
    <?
    $file = fopen("counter.txt", "r");
    $result = fread($file, filesize("counter.txt"));
    fclose($file);
    
    $hits = unserialize($result);
    $hits+=1;
    $result = serialize($hits);
    
    $file = fopen("counter.txt", "w");
    fwrite($file, $result);
    fclose($file);
    
    header("Location: http://path.to/site");
    
    ?>
    
    Code (markup):
    But the link in sitebar will be <a href="counter.php">link</a>

    With a little modification can count more links to more sites. This count only 1.
     
    sojic, Aug 27, 2006 IP
  3. Sullmoney

    Sullmoney Well-Known Member

    Messages:
    878
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Okay thanks. I will try this out today and see if it works.
     
    Sullmoney, Aug 28, 2006 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    A variation on sojic's script would not use a separate data base, but would utilize access.log the same as you would use it to track/count visits to your own pages.

    The request method would look like this,
    
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xml:lang="en"
          xmlns="http://www.w3.org/1999/xhtml"
          lang="en">
    <head>
      <meta http-equiv="content-type"
            content="text/html; charset=utf-8" />
    
      <meta name="generator"
            content=
            "HTML Tidy for Linux/x86 (vers 1st August 2004), see www.w3.org" />
    
      <meta name="editor"
            content="Emacs 21" />
      <meta name="author"
            content="Gary Turner" />
    
      <title>Referer Page</title>
    <style type="text/css">
    /*<![CDATA[*/
    
    html, body {
        margin: 0;
        padding: 0;
        }
    
    
    /*]]>*/
    </style>
    </head>
    
    <body>
    
    <h1>Links to be run through a redirector</h1>
    <ul>
      <li><a href="go.php?where=http://koko/~gt/webdev/target-1.html">target 1</a></li>
      <li><a href="go.php?where=http://koko/~gt/webdev/target-2.html">target 2</a></li>
      <li><a href="go.php?where=http://koko/~gt/webdev/target-3.html">target 3</a></li>
    </ul>
    </body>
    </html>
    Code (markup):
    And the response like so
    
    <? header ('location: '. $where) ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xml:lang="en"
          xmlns="http://www.w3.org/1999/xhtml"
          lang="en">
    <head>
      <meta name="generator"
            content=
            "HTML Tidy for Linux/x86 (vers 12 April 2005), see www.w3.org" />
    
      <meta name="editor"
            content="Emacs 21" />
      <meta name="author"
            content="Gary Turner" />
      <meta http-equiv="content-type"
            content="text/html; charset=utf-8" />
    
      <title>Send me on</title>
    <style type="text/css">
    /*<![CDATA[*/
    
    html, body {
        height: 100%;
        margin: 0;
        padding: 0;
        }
    
    body {
        text-align: center;
        }
    
    div {
        display: table;
        height: 100%;
        margin: 0 auto;
        vertical-align: middle;
        }
    
    div div {
        display: table-cell;
        }
    
    div div p {
        padding: 10px;
        border: ridge black;
    
    /*]]>*/
    </style>
    </head>
    
    <body>
      <div>
        <div>
          <p>If you aren't sent to the page, click this link.<br />
          [ <a href="<? echo $where ?>"> Send me on</a> ].</p>
        </div>
      </div>
    </body>
    </html>
    Code (markup):
    cheers,

    gary
     
    kk5st, Aug 28, 2006 IP
  5. sitethemouse

    sitethemouse Member

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    Statcounter.com works for this.
     
    sitethemouse, Dec 23, 2010 IP