Jump to content


Photo

Click Counter for links in my posts


  • Please log in to reply
2 replies to this topic

#1 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 March 2006 - 07:39 PM

Is there an easy way to add clicks to my DB for links that I post that direct users off my site?

So far this is what I have, but does not include any counting of any sort:

<?php

include 'library/config.php';
include 'library/opendb.php';

$id = (isset($_GET['id']) ? $_GET['id'] : "");
if (empty($id)) {


$rowsPerPage = 2;
$pageNum = 1; 
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage; 

$query = "SELECT id, title, url, description, thumbnail, DATE_FORMAT(entry_date, '%M %D %Y') AS date, category FROM plugs ORDER BY id DESC LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');

?>

<div class="title">Must Visit</div><p>&nbsp<br>

<?php
while($row = mysql_fetch_array($result)) { ?>



 <table width="460" border="0" align="center" cellpadding="1" cellspacing="0">
  <tr> 
        <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr> 
          <td width="18%" align="center" valign="top"> <div align="center"><a href="<?=$row['url'];?>"><IMG BORDER="0" img src="media/thumbs/<?=$row['thumbnail'];?>" height="80" width="80"></a></font><font face="Arial, Helvetica, sans-serif"> 
              </font></div></td>
          <td width="82%" align="center" valign="top"><div align="left"> 
              <table width="100%" border="0" cellspacing="5" cellpadding="0">

                <tr> 
                  <td><font size="2"><a href="<?=$row['url'];?>"><b><?php echo $row['title'];?></b></a>
<br><?php echo $row['description'];?></font></td>
                </tr>
                <tr> 
                  <td>&nbsp;</td>
                </tr>
              </table>
            </div></td>
        </tr>

        <tr> 
          <td colspan="2" align="center" valign="top"> <div align="left"> <font size="1">Submitted 
              On: <?php echo $row['date'];?> | xxx | Category: <?=$row['category'];?> | Clicks: 99</div></td></font>

        </tr>
      </table></td>
      </tr>
    </table>


#2 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 12 March 2006 - 08:09 PM

You would add a column to your database called clicks, then, make a referrer PHP file.. something like 'refer.php?to=http://www.google.com' and then, do the necessary checks. [=

It seems like you're proficient enough to figure out how to do that, so if you need more help don't hesitate to post!

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#3 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 March 2006 - 08:35 PM

[!--quoteo(post=354279:date=Mar 12 2006, 03:09 PM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 12 2006, 03:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You would add a column to your database called clicks, then, make a referrer PHP file.. something like 'refer.php?to=http://www.google.com' and then, do the necessary checks. [=

It seems like you're proficient enough to figure out how to do that, so if you need more help don't hesitate to post!
[/quote]

I'm not quite as proficient as I wish I was just yet... Mostly put together my scripts from mixing and matching from different scripts.

I have this script that I came across, and I use it for trading traffic where it calculates hits in and hits out. Apparently for perm linking you just need to do go.php?j=www.site.com but it doesn't seem to work for sites that aren't already sending traffic to my site:

<?php
/*
 * referers.php (c) plebian.com 1999-2004
 *
 * go.php
 * Jump to a url.
 */

if(isset($_SERVER['QUERY_STRING']))
{
    require_once('config.php');
    
    if(preg_match('!^[0-9]+$!',$_SERVER['QUERY_STRING']))
    {
        $id=&$_SERVER['QUERY_STRING'];
        $c=mysql_query("select id,url from TW_referers where id='{$id}'");
    }
    elseif(!empty($_GET['j']))
    {
        $url=addslashes($_GET['j']);
        $c=mysql_query("select id,url from TW_referers where url='$url' order by id desc limit 1");
    }
    else
    {
        $c=null;
    }

    $d=mysql_fetch_object($c);
    if(is_object($d))
    {
        mysql_query("update TW_referers set hitsout=hitsout+1 where id='{$d->id}'");
        $url=stripslashes($d->url);

        if(array_key_exists($url,$jump_url_replace))
            $url=$jump_url_replace[$url];
    }
    else
    {
        $url=&$_SERVER['SERVER_NAME'];
    }
}
else
{
    $url=&$_SERVER['SERVER_NAME'];
}

header("Location: http://$url");
exit;
?>

Also I guess I would need to add to this script to have it add clicks to my links DB, because right now its only adding to the referrers DB that is special for this go.php script.

Any suggestions?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users