Sign in to follow this  
Followers 0
Aztek

Great link tracking Script

5 posts in this topic

Great link tracking Script

This script is quite beautiful in it's simplicity

A user clicks a link to the url http://mysite.com/?id=123

the index.php file notices that the id is set and checks the database if id 123 exists,

if it does it will return the user this code

header("Location: http://www.linkto.com");
that will redirect the users client to www.linkto.com Run this mysql command on your mysql database
CREATE TABLE `linker` (

  `id` int(10) unsigned NOT NULL auto_increment,

  `path` varchar(255) NOT NULL default 'http://localhost',

  `comment` varchar(255) default 'no comment',

  `counter` int(10) NOT NULL default '0',

  PRIMARY KEY  (`id`)

) TYPE=MyISAM;
Put this code into index.php in the root of your domain
<?php

header("Cache-Control: no-cache, must-revalidate");


/* ERROR REPORTING ACTIVE !!! */

//error_reporting(E_ALL);


/*

 * Redirecter version 1.2

 *

 * ## THIS IS THE MAIN FILE

 *

 * Created by Aztek

*/


require_once('database.php');


if (isset($_GET['id']))

{

    CallToDb();


    $fileid = $_GET['id'];


    $mysqlresult = mysql_query('SELECT `path` FROM `linker` WHERE `id` = \'' . mysql_real_escape_string($fileid) . '\';');

    $stringvalue = mysql_fetch_row($mysqlresult);

    if (!$stringvalue)

    {

        //if user specifies invalid id return with

        die('<h1>An error has occurred...</h1><br /><h2>Incorrect ID or database error   !</h2>Error ID: 2 ( ' . mysql_error() . ' )</font>');

    }


    else

    {

        if ($_SERVER['REMOTE_ADDR'] == '000.000.000.000')

        {

            header('Location: ' . $stringvalue[0]);

            mysql_close();

            die();

        }

        else

        {

            mysql_query('UPDATE `linker` SET `counter` = `counter`+1 WHERE `id` = \'' . mysql_real_escape_string($fileid) . '\';');


            header('Location: ' . $stringvalue[0]);

            mysql_close();

            die();

        }

    }

}


// if ?id= is not defined return with...


/* !!! OPENS WEB !!! */

header('Location: path/to/your/main/site/');

mysql_close();

die();

/* !!! OPENS WEB !!! */

?>
change "if ($_SERVER['REMOTE_ADDR'] == '000.000.000.000')" to your ip so not to count your ip's clicks (or not and then no clicks will not be counted) now create database.php put this in there
<?php


/*

 * Redirecter version 1.2

 *

 * ## THIS FILE IS FOR DATABASE CONNECTION

 *

 * Written by Aztek

*/


// Settings

$database_username="put your database username here";

$database_password="put your database password here";

$database_name="put your database name here";

$hostname="put your database hostname (usually localhost) here";


function CallToDb()

{

    mysql_connect($hostname,$database_username,$database_password);

    mysql_select_db($database_name) or die( "Unable to select database" );

}


?>
Now, all you have to do is to add stuff to the database, For example...
INSERT INTO `linker` (`id`,`path`,`comment`,`counter`) VALUES 

 (' ','http://www.google.com','Google (external)',' ');
then open http://yoursite.com/?id=1 and you should see google.com, also the database will have 1 in the counter row... now when that's finished, it should be easy to make your own script to show the counter data or something like that :) i do have this admin area but i haven't tested it very much, i think it works though :) admin.php
<?php

header("Cache-Control: no-cache, must-revalidate");


/*

 * Redirecter version 1.2

 *

 * ## THIS IS THE ADMINISTRATION AREA

 *

 * Written by Aztek

*/


    require_once('database.php');

    CallToDb();


    if (isset($_POST['delete']))

    {

        mysql_query('DELETE FROM `linker` WHERE `id` = \'' . mysql_real_escape_string($_GET['delete']) . '\';');

        mysql_close();

    }


    if (isset($_POST['id']))

    {

        mysql_query('INSERT INTO `linker` (`id`, `path`, `comment`) VALUES (\'\', \'' . mysql_real_escape_string($_POST['path']) . '\')');

        mysql_close();

    }


    echo '<form method="POST">URI: <input type="text" name="path" value="http://" size="64"><br />Comment: <input type="text" name="comment" size="64"><br /><input type="submit" value="Add" name="submit"></form>';

    echo '<hr>';


        $mysqlresult = mysql_query('select * from `linker`');

        while ($testtext = mysql_fetch_row($mysqlresult))

        {

            echo '<a href="?delete=' . $testtext[0] . '">Delete</a>';

            echo '&nbsp;&nbsp;&nbsp;&nbsp;';

            echo '<b>id: </b> ' . $testtext[0];

            echo '&nbsp;&nbsp;&nbsp;&nbsp;';

            echo '<b>url: </b> ' . $testtext[1];

            echo '&nbsp;&nbsp;&nbsp;&nbsp;';

            echo '<b>Counter: </b> ' . $testtext[3];

            echo '&nbsp;&nbsp;&nbsp;&nbsp;';

            echo '<b>Comment: </b> ' . $testtext[2];

            echo '<br>';

        }


        echo '<html><head><title>Kjarni - ID System Administration</title></head><body>';

        echo '</body></html>';

}

?>

I am 90% sure there are some errors in the code but hey it works for me so far atleast, this script is awalible to anyone and anyone can make any modifications to it.

Thank you for wanting to use my script,

Aztek

gunni87@gmail.com

p.s. yes i made this script myself, although the php error handler helped me alot :)

Edited by Lee
Updated

Share this post


Link to post
Share on other sites

i love php too, you are welcome to use this script at will...

i was just told this script is just like microsofts fwlink system :(

for example they have http://go.microsoft.com/fwlink/?LinkId=xxxxx

mine is just cleaner (http://domain.com/?id=xxxx) :P but has potential for multi admin access (many users submitting id's)

Edited by Aztek

Share this post


Link to post
Share on other sites

would it be possible to disable the edit post timeout ?

atleast for subscribers :(

Edited by Aztek

Share this post


Link to post
Share on other sites

would it be possible to disable the edit post timeout ?

atleast for subscribers :(

It's global for all usergroups, so it's not possible. PM me with the changes you want to make and I'll update the post.

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0