jeg har lavet det efter en tutorial, som jeg fandt på nettet...
Hit counter (Database,PHP,Cookies)
When using this tutorial, it is assummed you know php basics and a little bit about sql.
Step 1_
Create a field namedcounter in your table.
Step 2_
Now create a file so we can connect to our database. Let's name it dbconnect.php.
<?
// Database connection
// SQL server
$host="localhost";
// SQL user
$user="username";
// SQL password
$password="password";
// Database name
$bdd="Name_of_your_Database_Here";
?>
Step 3_
Now that we have that file, we're continuing on to the counter script. Let's create a file named redirect.php.
<?
//Redirect.php allows to track hits on banners, buttons or links
// First, we need to include our file so we can connect to the database
include ("dbconnect.php");
// Connection is initialized
$link = mysql_connect ($host,$user,$password);
mysql_select_db($bdd, $link);
// First, we check that the url is not null. so we verify
if ($url!="")
{
// Now that we know the url is not null, we need to know if the file or the url we want to track exists in our database.
$req1="SELECT * from table where url='$url'"; // this SQL query supposes that you have a field named 'url' in your table
$res1=mysql_query($req1, $link);
$row1=mysql_fetch_object($res1);
$trouve=mysql_numrows(mysql_query($req1,$link));
// Will return 1 if the url has been found in the table
// We now have to find if there's already a cookie on the visitor's computer
if (!isset($clic[$url]) && $trouve!="")
{
// if he doesn't exists, we create the blocking cookie
SetCookie("clic[".$url."]","1",time()+3600*24); // The cookie will be destroyed 24 hours after being created
// we need to know what is the current number of hits in the counter
$counter=$row1->counter;
$counter++; // the counter is incremented
// Update of the counter in the table
$req2="UPDATE tablename SET counter='$counter' WHERE url='$url'";
mysql_query($req2, $link);
}
// Now we redirect the visitor to the url he clicked
mysql_free_result($res1); header("Location: ".$url);
}
?>
Step 4_
That's it, all you have to do now is put this link on the button you want to count :
<a href="redirect.php?url=
http://www.your_url.com">if you click this link it will be counted</a>