Hi!
Ive tried to install a counter-script that displays the number of pageloads on my forum. The forum is made in php and are using mysql-database to store the articles that are possible to submit on the site. Ive tried several different counters which have used the “include” command to include the script on the page, in my case content.php.
The problem is that the counter are counting the total number of pageloads on all of the articles alltogether, instead of counting the number of pageloads on every unique article. The page that are calling the articles from the database are as I said content.php and every article are named content.php?article.1, content.php?article.2, content.php?article.3 etc. the number refering to the number in the database.
My question is:
Are there anyone who got a script or any suggestion on how I can manage to view the number of pageloads on every unique article? I just manage to view the total amount of pageloads.
I guess I, somehow have to have a unique code for each article but the prolem is how and what kind of code?
Hope you understood my problem.
Thanks for your help
Per
PHP counter ... please help!
Moderator: General Moderators
Add something like below to your content.php (untested).
This only works in the case there is no session_id or something added to the url. In the case session_id is added to the url, you will have to get all the other chunks out of $_GET array, and build a session_id-free uri
And to display the number of hits:
This only works in the case there is no session_id or something added to the url. In the case session_id is added to the url, you will have to get all the other chunks out of $_GET array, and build a session_id-free uri
Code: Select all
mysql_connect(......);
mysql_select_db(......);
$uri = mysql_real_escape_string($_SERVER['REQUEST_URI']);
$query = "UPDATE pagehits SET count=count+1 WHERE uri='$uri'";
mysql_query($query);Code: Select all
mysql_connect(.....);
mysql_select_db(.....);
$uri = mysql_real_escape_string($_SERVER['REQUEST_URI']);
$query = "SELECT * FROM pagehits WHERE uri='$uri'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
print_r($row);mysql_connect(host,username,password);
mysql_select_db(name_of_database);
Whenever this script is ran, it will inc the value by one. Therefore place it in the php file you want to count from.
mysql_select_db(name_of_database);
Whenever this script is ran, it will inc the value by one. Therefore place it in the php file you want to count from.