Log in

View Full Version : Page Visit Counter



jnscollier
05-05-2007, 03:59 AM
Soooo, I found this awesome script in one of the threads :


<?php
$cdata = file_get_contents("counter.txt");
$ndata = ($cdata+1);
$handle = fopen("counter.txt","w+");
fwrite($handle,$ndata);
fclose($handle);
echo "\n<br>".$cdata." visits";
?>


But, here's my issue and i'm hoping someone can help me...
All my blogs go to one page and I pull from a SQL table and display the data for the particular blog selected... Example:

/viewblogdetails.php?blogid=205

ok, so I put the above script on that page and it of course increments every time the page is pulled up - regardless of the particular blog. I want to make a counter that counts only the views for a particular blog. Is that possible? Can I modify this code to make that?

Any help would be appreciated! Thanks! :eek:

djr33
05-05-2007, 04:47 AM
If you're using SQL, then wy not just use that to store the count?
Anyway, sure. Just find some way to create a specific text file per SQL item created.
For example, if you have $table set as the table you're searching in the database, then you could use $table.'counter.txt', which would be a specific file to the particular table used.
Or, instead of $table, use whatever data IS specific, such as the part of the SQL command with WHERE ____ = 'THIS'.
So, find the specific info, then use that in addition to the filename.

jnscollier
05-18-2007, 01:07 AM
I don't know why I didn't think of doing via SQL... but that's what I ended up doing, thanks! :)

djr33
05-18-2007, 03:30 AM
Best option. Glad it worked out.