Adding base files master
Adding base files

file:b/README.md (new)
--- /dev/null
+++ b/README.md
@@ -1,1 +1,2 @@
+This may or may not work, I've a newer build but need to remove the branding before I commit. Could do with a code tidy too!
 

--- /dev/null
+++ b/UrlbrandPrude.class.php
@@ -1,1 +1,48 @@
-
+<?php

+

+

+class UrlBrandPrude{

+

+/** Check the supplied string for any naughty strings

+*

+* @arg string - The string to be checked

+*

+* @return boolean - String approved by the censor? 

+*/

+

+function naughty_words($string){

+

+global $conf;

+

+foreach ($conf['app']['bannedstrings'] as $value){

+

+if(strpos($value,$string) === false){

+continue;

+}else{

+ return 0;

+}

+

+}

+

+return 1;

+

+

+

+

+}

+

+

+

+

+

+

+

+}

+

+

+

+

+

+

+

+?>

file:b/config.php (new)
--- /dev/null
+++ b/config.php
@@ -1,1 +1,34 @@
+<?php

+

+

+// Database details

+$conf['db']['dbhost'] = 'localhost';

+$conf['db']['dbname'] = '';

+$conf['db']['dbuser'] = '';

+$conf['db']['dbpass'] = '';

+

+// Domain name to use for generated links

+$conf['app']['url'] = "http://virya.co.uk";

+

+// Number of characters to use when generating short URLs

+$conf['app']['urichars'] = 6;

+

+// Maximum number of retries before giving up (when generating an urlcode)

+$conf['app']['retries'] = 10;

+

+// The display name of the site

+$conf['app']['name'] = "URL Brand";

+

+

+// Add any strings you don't want appearing into the array (rude word protection!)

+// Not yet implemented

+$conf['app']['bannedstrings'] = array("it","17","i7","ck","nt","ag","4g");

+

+$conf['app']['submitpass'] = "";

+

+

+

+

+

+?>

 

file:b/htaccess (new)
--- /dev/null
+++ b/htaccess
@@ -1,1 +1,19 @@
+RewriteEngine on

+

+

+RewriteCond %{REQUEST_URI} ^.*$

+

+RewriteRule ^([A-Za-z0-9]+)*$ "/index.php?url=$1" [L]

+

+

+

+RewriteCond %{REQUEST_URI} ^.*$

+

+RewriteRule ^([A-Za-z0-9]+\+)*$ "/index.php?info=1&url=$1" [L]

+ 

+

+

+RewriteCond %{REQUEST_URI} ^.*$

+RewriteRule ^([A-Za-z0-9]+\*)*$ "/index.php?qr=1&url=$1" [L]

+ 

 

file:b/index.php (new)
--- /dev/null
+++ b/index.php
@@ -1,1 +1,108 @@
+<?php

+

+require_once 'config.php';

+

+

+$url = $_GET['url'];

+

+// Should we show the main page?

+if (($url == "index.php") || (empty($url))){

+

+require_once 'shorturl.html.php';

+$html = new shorturl_html;

+

+

+// Are we adding an URL?

+if (!empty($_POST['newurl'])){

+// Authenticate the request

+require_once 'urlbrand_auth.class.php';

+

+$auth = new UrlBrand_auth;

+$authres = $auth->simpleauth($_POST['pass']);

+

+if (!$authres){

+echo "Access Denied - Invalid Password";

+die;

+}

+

+

+// Add an URL

+require_once 'newurl.class.php';

+$url = new newurl;

+$shortened_url = $url->add_url($_POST['newurl']);

+

+}

+

+

+$html->html_init($shortened_url);

+

+

+

+

+

+}else{

+

+// See if this request is the result of a QR Code being scanned

+if ($_GET['qr'] == 1){

+

+$url = substr($url,0,-1);

+

+$_SERVER['HTTP_REFERER'] = "QR Code";

+}

+

+

+// No, need to redirect or show info page

+

+require_once 'shorturl_existing.class.php';

+

+$info = new shorturl_existing;

+

+

+

+

+if ($_GET['info'] == "1"){

+// Show info page

+

+require_once 'shorturl.html.php';

+$html = new shorturl_html;

+

+$origurl = substr($url,0,-1);

+$info->load_url_info($origurl);

+

+

+// Call the template

+$html->html_init($info);

+

+

+

+

+}else{

+// Load the original url and redirect

+$info->load_redir($url);

+}

+

+

+

+

+

+}

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+?>

 

file:b/newurl.class.php (new)
--- /dev/null
+++ b/newurl.class.php
@@ -1,1 +1,167 @@
+<?php

+

+

+require_once 'urlshortdb.class.php';

+

+

+

+

+

+

+

+

+

+class newurl{

+

+

+/** Generate a URL identifier

+*

+*/

+function generate_urlcode(){

+global $conf;

+

+// Load the chars array

+$chars = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',

+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',

+ '0','1','2','3','4','5','6','7','8','9');

+

+

+

+// Generate the random string

+$X = 1;

+while ($X <= $conf['app']['urichars']){

+

+$selection_no = rand(1,62);

+

+$str .= $chars[$selection_no];

+$X++;

+}

+

+

+$this->urlcode = $str;

+

+

+}

+

+

+

+

+/** See if the submitted URL already exists in the database

+*

+*/

+function check_longurl_exist(){

+

+$this->exists = $this->db->load_by_longurl($this->url);

+

+

+}

+

+

+

+

+

+/** Check whether the provided URLCode is actually unique

+*

+*/

+function check_urlcode_unique(){

+

+

+$result = $this->db->load_by_urlcode($this->urlcode);

+

+if($result){

+

+$this->unique = 1;

+}else{

+$this->unique = 0;

+}

+

+

+

+}

+

+

+

+

+

+/** Main Entry Point

+* 

+* @arg $url - String containing URL to be shortened

+*

+* @return string - Shortened URL

+*

+*/

+function add_url($url){

+

+// Set some vars

+global $conf;

+$this->url = $url;

+$this->db = new urlshort_db;

+

+// Check if the URL already exists in the DB - TODO

+$this->check_longurl_exist();

+

+$row = mysql_fetch_object($this->exists);

+

+if (!isset($row->shURL)){

+

+// load the Censor

+require_once 'UrlbrandPrude.class.php';

+

+// Generate the URL code (might take a few tries to get a unique one)

+// Cap maximum number of retries

+$X = 1;

+while (($this->unique != 1) && ($this->approved != 1)){

+$this->generate_urlcode();

+$this->check_urlcode_unique();

+

+

+$prude = new UrlBrandPrude;

+$this->approved = $prude->naughty_words($this->urlcode);

+

+

+if ($X == $conf['app']['retries']){

+

+$this->error = Y;

+$this->errortext = "Maximum number of URL generation retries hit - could not continue";

+return $this;

+}

+

+$X++;

+}

+

+$this->created_date = date('Y:m:d H:i:s');

+

+// Add the Url to the database

+

+$this->add_status = $this->db->save_new_url($this);

+}else{

+

+

+

+

+$this->add_status = true;

+$this->urlcode = $row->shURL;

+

+}

+

+

+

+return $this;

+

+}

+

+

+

+

+

+}

+

+

+

+

+

+

+

+

+?>

 

file:b/shorturl.html.php (new)
--- /dev/null
+++ b/shorturl.html.php
@@ -1,1 +1,201 @@
+<?php

+

+

+

+class shorturl_html{

+

+/** Generate Stats Page for specified URL

+*

+*/

+function url_info($url){

+

+require_once 'urlbrand_barcodes.class.php';

+

+$urlbrand = new UrlBrand_barcodes;

+$link = "{$this->url_pref}/{$url->url->urlcode}*";

+$qr = $urlbrand->generate_QR_Code($link);

+

+$str .= "<span class='title'>Information for URL {$this->url_pref}/{$url->url->urlcode}</span>\n <br /><br>\n" .

+'<table class="urlinfo"><tbody>' .

+'<tr class="infohead"><td>URL</td><td>Short URL</td><td>Created</td><td>Hits</td><td>QR Code</td></tr>' . "\n" .

+'<tr class="infodata"><td>' .

+"\n <a href=\"{$url->url->url}\" target=_blank class=\"originallink\">{$url->url->url}</a>\n</td><td>" .

+"\n <a href=\"{$this->url_pref}/{$url->url->urlcode}\" target=_blank class=\"shortlink\">{$url->url->urlcode}</a>\n</td><td>" .

+"\n {$url->url->created}\n</td><td>\n" .

+"\n {$url->url->hits}\n</td><td>{$qr->html}</td></tr>\n" .

+"</tbody>\n</table>";

+

+

+

+// The query may have failed, or hits might be 0 so check before trying to generate the referers table

+if (isset($url->referers)){

+

+// Generate the table

+$str .= "<br /><br />\n\n\n<span class=\"toprefererstitle\">Top Referers</span><br />" .

+"<table class=\"topreferers\"><tbody>\n" .

+"<tr class=\"toprefererstitle\"><td>Referer</td><td>Hits</td><td>First Seen</td><td>Last Seen</td></tr>";

+

+foreach ($url->referers as $value){

+

+$str .= "<tr class=\"toprefersdata\"><td><a href=\"{$value->Referer}\" rel=\"nofollow\" class=\"originallink\">{$value->Referer}</a>" .

+"</td><td>{$value->Hits}</td><td>{$value->FirstSeen}</td><td>{$value->lastseen}</td></tr>\n";

+

+

+

+}

+

+

+$str .= "</tbody>\n</table>\n";

+

+

+}

+

+

+

+

+if (isset($url->uas->top)){

+

+// Generate the table

+$str .= "<br /><br />\n\n\n<span class=\"toprefererstitle\">Most Common User Agent</span><br />" .

+"<table class=\"topreferers\"><tbody>\n" .

+"<tr class=\"toprefererstitle\"><td>User Agent</td><td>Hits</td><td>First Seen</td><td>Last Seen</td></tr>";

+

+foreach ($url->uas->top as $value){

+

+$str .= "<tr class=\"toprefersdata\"><td>{$value->UserAgent}" .

+"</td><td>{$value->Hits}</td><td>{$value->FirstSeen}</td><td>{$value->lastseen}</td></tr>\n";

+

+

+

+}

+

+

+$str .= "</tbody>\n</table>\n";

+

+

+

+

+}

+

+

+

+if (isset($url->uas->bottom)){

+

+// Generate the table

+$str .= "<br /><br />\n\n\n<span class=\"toprefererstitle\">Least Common User Agent</span><br />" .

+"<table class=\"topreferers\"><tbody>\n" .

+"<tr class=\"toprefererstitle\"><td>User Agent</td><td>Hits</td><td>First Seen</td><td>Last Seen</td></tr>";

+

+foreach ($url->uas->bottom as $value){

+

+$str .= "<tr class=\"toprefersdata\"><td>{$value->UserAgent}" .

+"</td><td>{$value->Hits}</td><td>{$value->FirstSeen}</td><td>{$value->lastseen}</td></tr>\n";

+

+

+

+}

+

+

+$str .= "</tbody>\n</table>\n";

+

+

+

+

+}

+

+

+

+

+

+$this->htmlcontent = $str;

+

+}

+

+

+

+/** Generate page content following submission of a URL

+*

+*/

+function shortened_url($url){

+require_once 'urlbrand_barcodes.class.php';

+

+$urlbrand = new UrlBrand_barcodes;

+$qr = $urlbrand->generate_QR_Code($this->url_pref."/".$url->url->urlcode."*");

+

+

+$this->htmlcontent .= '<table class="urlinfo"><tbody>' .

+'<tr class="infohead"><td>URL</td><td>Short URL</td><td>View Stats</td><td>QR Code</td></tr>' . "\n" .

+'<tr class="infodata"><td>' .

+"\n <a href=\"{$url->url}\" target=_blank class=\"originallink\">{$url->url}</a>\n</td><td>" .

+"\n <a href=\"{$this->url_pref}/{$url->urlcode}\" target=_blank class=\"shortlink\">{$url->urlcode}</a>\n</td><td>" .

+"\n <a href=\"{$this->url_pref}/{$url->urlcode}+\" target=_blank class=\"statslink\">URL Stats\n</td><td>{$qr->html}</td></tr>\n" .

+"</tbody>\n</table>";

+

+

+

+}

+

+

+

+/** Generate form allowing submission of URL for shortening

+*

+*/

+function generate_shorten_form(){

+

+

+$this->htmlcontent .= '<form action="index.php" method="post" class="submitform">' .

+'<input type="text" name="newurl" class="inputbox" value="' . $_POST['newurl'] . '">' . "\n";

+global $conf;

+

+if (!empty($conf['app']['submitpass'])){

+$this->htmlcontent .= '<input type="password" name="pass">';

+

+}

+

+$this->htmlcontent .= '<input type="submit" value="Shorten!" class="button"></form>';

+

+

+}

+

+

+

+

+// Generate the HTML content before invoking the template

+function html_init($url){

+

+global $conf;

+$this->url_pref=$conf['app']['url'];

+$this->app_name = $conf['app']['name'];

+

+$this->generate_shorten_form();

+

+if ($url->error=="Y"){

+$this->htmlcontent = "<span class='error'>{$this->errortext}</span>\n";

+}

+

+

+// Have we added?

+if ($url->add_status){

+$this->shortened_url($url);

+}

+

+

+// We are displaying the URL info page

+if (isset($url->url->url)){

+$this->url_info($url);

+}

+

+

+

+// invoke the template

+include 'template.php';

+

+}

+

+

+

+

+}

+

+?>

 

--- /dev/null
+++ b/shorturl_existing.class.php
@@ -1,1 +1,165 @@
+<?php

+

+require_once 'urlshortdb.class.php';

+

+

+class shorturl_existing{

+

+

+/** Get the original URL from the database and redirect

+*

+*/

+function load_redir($url){

+global $conf;

+// Load the URL from the DB and send a redirection header

+$this->db = new urlshort_db;

+$res = $this->db->load_by_urlcode($url);

+$row = mysql_fetch_array($res);

+

+

+if (empty($row['lURL'])){

+echo "URL not found, is it valid?";

+die;

+}

+

+

+$location = stripslashes($row['lURL']);

+header("Location: $location\n\r");

+

+

+// Now input the stats

+$this->db->increase_hit_count($url);

+

+if ((!empty($_SERVER['HTTP_REFERER'])) && ($_SERVER['HTTP_REFERER'] != $conf['app']['url'] . "/" . $url . "+")){

+$this->db->add_referer($url,$_SERVER['HTTP_REFERER']);

+

+}

+

+if (!empty($_SERVER['HTTP_USER_AGENT'])){

+

+$this->db->add_user_agent($url,$_SERVER['HTTP_USER_AGENT']);

+

+}

+

+

+}

+

+

+

+

+

+

+

+

+

+/** Grab the Info needed for the URL summary

+*

+*/

+

+function load_url_info($url){

+

+$this->db = new urlshort_db;

+

+// Load the URL from the DB along with associated info

+$url_info = $this->db->retrieve_full_url_info($url);

+

+if ($url_info){

+$row = mysql_fetch_array($url_info,MYSQL_ASSOC);

+

+$this->url->url = $row['lURL'];

+$this->url->urlcode = $url;

+

+$created = strtotime($row['Added']);

+$this->url->created = date('d/m/Y H:i',$created);

+

+

+

+// Get Info on number of hits

+$hits = $this->db->retrieve_hitcount($url);

+

+if ($hits){

+$row = mysql_fetch_array($hits,MYSQL_ASSOC);

+$this->url->hits = $row['Hits'];

+}

+

+

+// Get Info on Top Referers (if any) and user agents

+if ($this->url->hits > 0){

+

+$refs = $this->db->retrieve_top_referers($url);

+

+if ($refs){

+

+$X = 1;

+while ($row = mysql_fetch_object($refs)){

+

+$this->referers->$X = $row;

+$X++;

+}

+

+

+}

+

+// Get info on the most common User-Agents 

+$uas = $this->db->retrieve_top_uas($url);

+

+if ($uas){

+

+$X = 1;

+while ($row = mysql_fetch_object($uas)){

+$this->uas->top->$X = $row;

+$X++;

+}

+

+}

+

+

+// Get info on any unusual User-Agents recorded for this URL (based on hits)

+

+$uas = $this->db->retrieve_bottom_uas($url);

+

+if ($uas){

+

+$X = 1;

+while ($row = mysql_fetch_object($uas)){

+$this->uas->bottom->$X = $row;

+$X++;

+}

+

+}

+

+

+

+}

+

+

+

+

+

+}else{

+// URL not found

+$this->error = "Y";

+$this->errortext = "The URL you specified was not found";

+}

+

+

+

+return $this;

+

+}

+

+

+

+

+

+

+

+

+

+

+

+}

+

+

+?>

 

file:b/template.php (new)
--- /dev/null
+++ b/template.php
@@ -1,1 +1,53 @@
-
+<?php

+

+if (!empty($this->url)){

+$title = " - {$this->url_pref}/{$this->url}";

+}

+

+if (!empty($this->url->url)){

+$title = " - {$this->url_pref}/{$this->url->url}";

+}

+

+

+?>

+

+<html>

+<head>

+<title><?php echo $this->app_name . $title; ?></title>

+

+

+

+<style type="text/css">

+<!--

+

+body { background: white; color: black;}

+span.title {text-align: center; font-weight: bolder; font-size: larger}

+

+table.urlinfo {border: 0;}

+tr.infohead{text-align: center; font-weight: bolder;}

+tr.infodata{text-align: center; font-weight: normal;}

+span.toprefererstitle{font-weight: bolder;}

+

+table.topreferers{border:0}

+tr.toprefererstitle{text-align: center; font-weight: bolder;}

+tr.toprefersdata{text-align: center; font-weight: normal;}

+

+input.inputbox{font-size: normal}

+input.button{font-size: smaller}

+

+a:originallink{text-decoration: none}

+a:shortlink {text-decoration: none}

+a:statslink {text-decoration: none}

+-->

+

+</style>

+</head>

+<body>

+<span class="title"><?php echo $this->app_name . $title; ?></span>

+

+

+<?php echo $this->htmlcontent; ?>

+

+

+</body>

+</html>

--- /dev/null
+++ b/urlbrand_auth.class.php
@@ -1,1 +1,55 @@
+<?php

+

+

+

+class UrlBrand_auth{

+

+

+/** Checks whether the password matches one set in the config

+*

+* @arg pass - supplied password

+*

+* @return boolean

+*/

+function simpleauth($pass){

+

+global $conf;

+

+$pass = md5($pass);

+if ($pass == $conf['app']['submitpass']){

+return true;

+}

+

+return false;

+

+

+}

+

+

+

+

+

+

+

+

+

+

+}

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+?>

 

--- /dev/null
+++ b/urlbrand_barcodes.class.php
@@ -1,1 +1,39 @@
+<?php

+

+

+class UrlBrand_barcodes{

+

+

+/** Uses Google Chart API to generate a QR Code

+*

+* @arg url - URL to generate the code for

+* @arg width - Width

+* - Note Height not specified as code must be square!

+*

+* @return - object - URL to view the Image & HTML code

+*/

+function generate_QR_Code($url, $width=150){

+$url = urlencode($url);

+

+

+$this->url = "http://chart.apis.google.com/chart?chs=" . $width . "x" . $width .

+"&cht=qr&chld=H|0&chl=" . $url;

+

+$this->html = "<img src='{$this->url}' width='$width' height='$width' alt='QR Code " .

+"- Scan with barcode scanner to load' title='QR Code - Scan with barcode scanner to load'>";

+

+

+return $this;

+

+}

+

+

+

+}

+

+

+

+

+

+?>

 

--- /dev/null
+++ b/urlshortdb.class.php
@@ -1,1 +1,289 @@
+<?php

+

+class urlshort_db{

+

+

+function open_db(){

+global $conf;

+

+// Open the Database connection

+$this->link = mysql_connect($conf['db']['dbhost'], $conf['db']['dbuser'], $conf['db']['dbpass']);

+

+if (!$this->link) {

+    die('Could not connect: ' . mysql_error());

+}

+else

+{

+

+// Connect to a specific database if one is named

+if (!empty($conf['db']['dbname'])){

+$db_selected = mysql_select_db($conf['db']['dbname'], $this->link);

+if (!$db_selected) {

+    die ('Can\'t use ' . $conf['db']['dbname'] . ': ' . mysql_error());

+}

+

+}

+}

+return $this->link;

+

+

+

+

+

+}

+

+

+

+

+function close_db(){

+

+

+

+mysql_close($this->link);

+

+

+}

+

+

+

+

+

+

+/** Retrieve URL information from the Database using the URL code

+*

+*/

+function load_by_urlcode($code){

+// Need to open the DB

+$this->open_db();

+

+$code = mysql_real_escape_string($code);

+

+$query = "SELECT lURL FROM URLs WHERE shURL='$code'";

+$result = mysql_query($query);

+$this->close_db();

+return $result;

+

+

+

+}

+

+

+

+/** Retrieve URL details using the Long URL

+*

+*/

+function load_by_longurl($url){

+$this->open_db();

+$url = mysql_real_escape_string($url);

+

+$query = "SELECT shURL FROM URLs WHERE lURL='$url'";

+$result = mysql_query($query);

+

+$this->close_db();

+return $result;

+

+}

+

+

+

+

+

+

+/** Store a new URL in the database

+*

+*/

+function save_new_url($data){

+

+// Need to Open the DB

+

+$this->open_db();

+

+$shURL = mysql_real_escape_string($data->urlcode);

+$lURL = mysql_real_escape_string($data->url);

+$user = mysql_real_escape_string($data->user);

+

+

+$query = "INSERT INTO URLs(shURL,lURL,Added,User)" .

+" VALUES('$shURL','$lURL','{$data->created_date}','$user')";

+

+$result = mysql_query($query);

+echo mysql_error();

+

+$this->close_db();

+return $result;

+

+}

+

+

+

+/** Record a new hit on a Short URL

+*

+*/

+function increase_hit_count($url){

+

+// Need to open the DB

+$this->open_db();

+

+$url = mysql_real_escape_string($url);

+$query = "INSERT INTO Stats (URLID,Hits) VALUES ('$url','1') " . 

+"ON DUPLICATE KEY UPDATE Hits=Hits+1";

+

+$result = mysql_query($query);

+echo mysql_error();

+

+$this->close_db();

+return $result;

+

+}

+

+

+

+/** Record a new referer or update the hit count if referer exists

+*

+*/

+function add_referer($url,$referer){

+

+// Need to Open the DB

+$this->open_db();

+$referer = mysql_real_escape_string($referer);

+$url = mysql_real_escape_string($url);

+$date = date('Y-m-d H:i:s');

+

+$query = "INSERT INTO Referers (URLID,Referer,Hits,Firstseen,lastseen) VALUES('$url','$referer','1','$date','$date')" .

+" ON DUPLICATE KEY UPDATE Hits=Hits+1,lastseen='$date'";

+$result = mysql_query($query);

+echo mysql_error();

+

+$this->close_db();

+return $result;

+

+

+}

+

+

+/** Record a new useragent or update the hit count if referer exists

+*

+*/

+function add_user_agent($url,$ua){

+

+// Need to Open the DB

+$this->open_db();

+$ua = mysql_real_escape_string($ua);

+$url = mysql_real_escape_string($url);

+$date = date('Y-m-d H:i:s');

+

+$query = "INSERT INTO UserAgents (URLID,UserAgent,Hits,FirstSeen,lastseen) VALUES('$url','$ua','1','$date','$date')" .

+" ON DUPLICATE KEY UPDATE Hits=Hits+1,lastseen='$date'";

+$result = mysql_query($query);

+echo mysql_error();

+

+$this->close_db();

+return $result;

+

+

+}

+

+

+/** Retrieve URL data for the stats page

+*

+*/

+function retrieve_full_url_info($url){

+// Need to open the db

+$this->open_db();

+

+

+$url = mysql_real_escape_string($url);

+

+$query = "SELECT * FROM URLs WHERE shURL='$url'";

+$result = mysql_query($query);

+

+

+$this->close_db();

+return $result;

+

+

+}

+

+

+/** Retrieve the number of times a URL has been loaded

+*

+*/

+function retrieve_hitcount($url){

+$this->open_db();

+$url = mysql_real_escape_string($url);

+$query = "SELECT Hits FROM Stats WHERE URLID='$url'";

+$result = mysql_query($query);

+

+$this->close_db();

+return $result;

+

+

+

+}

+

+

+

+/** Retrieve the top 10 referers

+*

+*/

+function retrieve_top_referers($url){

+$this->open_db();

+

+$url = mysql_real_escape_string($url);

+$query = "SELECT * FROM Referers WHERE URLID='$url' ORDER BY Hits Desc LIMIT 10";

+$result = mysql_query($query);

+

+

+$this->close_db();

+return $result;

+

+

+}

+

+

+

+

+/** Retrieve the top 10 user-agents

+*

+*/

+function retrieve_top_uas($url){

+$this->open_db();

+

+$url = mysql_real_escape_string($url);

+$query = "SELECT * FROM UserAgents WHERE URLID='$url' ORDER BY Hits Desc LIMIT 10";

+$result = mysql_query($query);

+

+

+$this->close_db();

+return $result;

+

+

+}

+

+/** Retrieve the top 10 user-agents

+*

+*/

+function retrieve_bottom_uas($url){

+$this->open_db();

+

+$url = mysql_real_escape_string($url);

+$query = "SELECT * FROM UserAgents WHERE URLID='$url' ORDER BY Hits Asc LIMIT 10";

+$result = mysql_query($query);

+

+

+$this->close_db();

+return $result;

+

+

+}

+

+

+}

+

+

+

+

+

+

+?>