
How do I have a counter for a link?!
Moderator: General Moderators
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
How do I have a counter for a link?!
Ok look below, i'm lookin for a script that can count the total clicks on a link when u do a mouse over like shown below. Plz help


-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
Lets say the link goes to "page2.php", and that you have file named "counter.txt" that contains an integer (the number of times the link has been clicked).
on page2.php, put the following code
I am certain that there is a way to do this without closing and re-opening the file, but my brain is not really working at the moment.
on page2.php, put the following code
Code: Select all
<?
// only process if you came from index.php
if($_SERVER['HTTP_REFERER']=="www.yoursite.com/index.php"){ // or whatever the index page is named
// open counter.txt and read the current value
$fp=fopen("counter.txt","r");
$counter=fread($fp,filesize("counter.txt"));
// increment the value
$counter++;
fclose($fp);
// write the value
$fp=fopen("counter.txt","w");
fwrite($fp,$counter);
fclose($fp);
}
?>-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
This will work..
Instead of linking directly to the new site the user will be taken through this page without knowing it.
Just put this code into a file called link.php or something and then in your link(s) href put ... href="links.php?sitename=name_of_website"
Then when that link is used the php page loads, updates the count, and then goes directly to the site.
You will need to add your sites into the code below..
..why didn't you just ask the person who put your site together?
Instead of linking directly to the new site the user will be taken through this page without knowing it.
Just put this code into a file called link.php or something and then in your link(s) href put ... href="links.php?sitename=name_of_website"
Then when that link is used the php page loads, updates the count, and then goes directly to the site.
You will need to add your sites into the code below..
Code: Select all
<?php
//list of links
if($sitename=="site_name_one") { $countfile = "site_name_one.txt"; $url="http://the_sites_web_address"; }
if($sitename=="site_name_two") { $countfile = "site_name_two.txt"; $url="http://the_sites_web_address"; }
// open count file and read the current value
// make sure the .txt files are in the same folder as the php file
$fp=fopen($countfile,"r");
$counter=fread($fp,filesize($countfile));
// increment the value
$counter++;
fclose($fp);
// write the value
$fp=fopen($countfile,"w");
fwrite($fp,$counter);
fclose($fp);
header('location:'.$url);
?>..why didn't you just ask the person who put your site together?
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
ahhhh nvm still not how its like on http://www.shiver7.com just forget it. And i'm the one who put my site together LOL
http://saiyanarmy.paradoxquest.com
http://saiyanarmy.paradoxquest.com
WHAT IS YOUR PROBLEM?!?!
The script above does exactly what you asked for..... it counts the number of times a user goes to a different site via a link!
If this isn't what you wanted then try learn some f**king english and ask your question properly.
Don't come onto this site, ask a question, and then get moody because no-one has a clue what they are supposed to be helping you with.

The script above does exactly what you asked for..... it counts the number of times a user goes to a different site via a link!
If this isn't what you wanted then try learn some f**king english and ask your question properly.
Don't come onto this site, ask a question, and then get moody because no-one has a clue what they are supposed to be helping you with.
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas