Publishing System Settings Logout Login Register
Learn how to create a Referal Log
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on March 3rd, 2007
4056 views
PHP Coding
In this tutorial I'm going to create a script which records any sites which link to yours. To begin with we are going to record the referals. To begin with we need to make the table. The SQL code is

CREATE TABLE `referals` ( 
`ref_id` int(5) NOT NULL auto_increment,
`ref_site` varchar(255) NOT NULL default '',
`ref_timedate` timestamp NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`ref_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;




To begin with we need to get the referal address and clean it up.

include "conn.php";
$ref = @$_SERVER['HTTP_REFERER'];
$ref = eregi_replace('http://', '', $ref);
$ref = eregi_replace('www.', '', $ref);
$ref = explode('/',$ref);
$ref = $ref[0];


The first line is just the database connect details. Then we move on to getting the address from which you where refered from. Now we need to clean up the address to prepare it too be stored.

$ref = eregi_replace('http://', '', $ref); 
$ref = eregi_replace('www.', '', $ref);


To begin with we are going to remove the http://www. from the url by using the eregi_replace function.

 eregi_replace('What your searching for','What we are replacing it with',what you want the end result stored as)


Next we need to get rid off any trailing details from the refering url. We use the explode function to get split up whats before the / and after it. The explode function splits the selected string into an array of all the values between the "/".

Now we need to store this into the database but we don't want to store your sites domain over and over agian. So we add in this check.

if ($ref == "arutha.co.uk"){ 

}else{


Just replace arutha.co.ukwith your domain. If the domain isn't equal to the refering address then its stored using the following query.

$insert = mysql_query("INSERT INTO `referals` ( `ref_id` , `ref_site` , `ref_timedate` ) VALUES ( 'NULL', '$ref', NOW( ) );") or die('Unable to insert your referer'); }


Just your standard SQL Insert query.

You want to put this code at the top off your page so it records it.

Thats about it

Arutha
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Arutha

As much as i love the default message i want to just say hello and to tell you to visit my blog :)
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top