Posted on March 3rd, 2007
4056 views
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` ( To begin with we need to get the referal address and clean it up. include "conn.php"; 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); 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"){ 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 |