click.php
db.php
index.html
stats.php
dump.sql
| Code: |
| <?php
// Click counter $day = date("Y-m-d"); // format the date like it is written in the database if ($QUERY_STRING) { include("db.php"); // connect to the database $url = urldecode($QUERY_STRING); $result = mysql_query("SELECT * FROM clickout WHERE url='$url' AND day='$day'",$db); if(mysql_num_rows($result) > 0) { mysql_free_result($result); $result = mysql_query("SELECT UNIX_TIMESTAMP(time) FROM ip WHERE (url='$url' AND ipnum='$REMOTE_ADDR' AND day='$day')",$db); if($row = mysql_fetch_row($result)) { if(($row[0]+3600) < time()) { mysql_query("UPDATE clickout SET raw=raw+1,uni=uni+1 WHERE url='$url' AND day='$day'",$db); mysql_query("UPDATE ip SET time=NOW() WHERE url='$url' AND ipnum='$REMOTE_ADDR' AND day='$day'",$db); } else { // the click is raw mysql_query("UPDATE clickout SET raw=raw+1 WHERE url='$url' AND day='$day'",$db); } mysql_free_result($result); } else { // it's a new ip mysql_query("UPDATE clickout SET raw=raw+1,uni=uni+1 WHERE url='$url' AND day='$day'",$db); mysql_query("INSERT INTO ip (url,ipnum,day) VALUES ('$url','$REMOTE_ADDR','$day')",$db); } } else { // it's a new url or day mysql_query("INSERT INTO ip (url,ipnum,day) VALUES ('$url','$REMOTE_ADDR','$day')",$db); mysql_query("INSERT INTO clickout (url,day,raw,uni) VALUES ('$url','$day',1,1)",$db); } $url="Location: ".$url; header($url); exit; } ?> |
db.php
| Code: |
|
<?php $dbhost = "localhost"; $dbuser = "user"; $dbpasswd = "password"; $db=mysql_connect("$dbhost","$dbuser","$dbpasswd"); mysql_select_db("count",$db); ?> |
index.html
| Code: |
| <html>
<body bgcolor="#FFFFFF"> <a href="click.php?http://slashdot.org/">A test link...</a><br> <a href="click.php?http://www.slashdot.org/">Another test link...</a><br> <a href="click.php?http://slashdot.com/">Jet another one...</a><br> <a href="click.php?http://www.slashdot.com/">You won't believe, it's a link...</a><br> <p> <a href="click.php?stats.php">Click Statistics</a> </p> </body> </html> |
stats.php
| Code: |
|
<html> <head> <title>Click Statistics</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1250"> <style type="text/css"> <!-- td { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; text-decoration: none} p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; text-decoration: none} a { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-decoration: none} --> </style></head> <body bgcolor="#999999" text="#333333" link="#9999FF" vlink="#3399FF" alink="#0099FF"> <table width="90%" border="0" cellspacing="2" cellpadding="2" align="center" bgcolor="#000000"> <tr bgcolor="#FFFFCC"> <td>Click statistics...</td> </tr> <tr bgcolor="#FFFFCC"> <td> <p>This are the statistics for all your pages grouped by days...</p> <?php include("db.php"); // connect to the base $lastday = " "; $result = mysql_query("SELECT * FROM clickout ORDER BY day DESC",$db); while($row = mysql_fetch_array($result)) { if(!strstr($lastday,$row['day'])) { if($lastday != " ") { print("</table><br>\n"); } // if it is empty don't terminate the table because it does not exist // table formatting print("<table width=\"80%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" align=\"center\" bgcolor=\"#009999\">\n"); printf("<tr><td bgcolor=\"#009999\" colspawn=\"3\" align=\"center\"><b><font color=\"#FFFFCC\">%s</font></b></td></tr>",$row['day']); print("<tr><td><b><font color=\"#FFFFCC\">URL</font></b></td><td><b><font color=\"#FFFFCC\">raw</font></b></td><td><b><font color=\"#FFFFCC\">unique</font></b></td></tr>"); } printf("<tr><td bgcolor=\"#FFFFCC\">%s</td><td bgcolor=\"#FFFFCC\">%s</td><td bgcolor=\"#FFFFCC\">%s</td></tr>",$row['url'],$row['raw'],$row['uni']); $lastday = $row['day']; } ?> </table> </td> </tr> </table> </body> </html> |
dump.sql
| Code: |
| # phpMyAdmin MySQL-Dump
# http://phpwizard.net/phpMyAdmin/ # # Host: localhost Database : count # -------------------------------------------------------- # # Table structure for table 'clickout' # CREATE TABLE clickout ( day date DEFAULT '0000-00-00' NOT NULL, url varchar(120) NOT NULL, raw int(11) NOT NULL, uni int(11) NOT NULL ); # -------------------------------------------------------- # # Table structure for table 'ip' # CREATE TABLE ipclick ( day date DEFAULT '0000-00-00' NOT NULL, url varchar(120) NOT NULL, time timestamp(14), ipnum varchar(15) NOT NULL ); |
