View Full Version : number of views script
Hello, I am looking for a script that shows the number of views for a picture, video and etc. Please and thank you!
tech_support
01-09-2008, 12:52 AM
counter.inc.php:
<?php
if (!isset($_SESSION)) {
session_start();
}
$page = urlencode($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'].'.counter');
if (!file_exists('counter/')) {
mkdir('counter');
}
$visits = file_exists('counter/'.$page) ? (int)file_get_contents('counter/'.$page) : 0;
if (!isset($_SESSION['counter'])) {
$visits++;
createFile('counter/'.$page,$visits);
$_SESSION['counter'] = 'counted';
}
function createFile($file,$content) {
$mode='w+';
$fp = fopen($file,$mode);
fwrite($fp,$content);
fclose($fp);
}
?>
Add this to the very top of your page where you want to add the counter:
<?php include('counter.inc.php'); ?>
And to get the visits put this where you want it:
<p><?php echo $visits; ?> visits.</p>
One visit is counted per browser session, aka. when you open your browser and visit that page it's a visit.
Master_script_maker
01-09-2008, 01:27 AM
Previous zip taken out
here, i made this one (but it only works for the whole site's visits)
demo: http://masterproject.freehostia.com/counter/hits.php
read the readme and do the stuff stated.
(it also comes in blue, green, and text, or you own custom images.)
i combined thetestingsite and my script to get this, you include and echo it the same, but a formated table outputs when you echo it.(you can use the images from the zip, or text):
<?php
$type=".gif"; //type of img ex. .gif .png .jpg (include the period) or type text if you want it to be text
//don't define below if type is set to text
$url="red/"; //path of images with / ex. red/ . (not complete url, just relative to the php file)(name images in the folder 0,1,2,3,4,5,6,7,8,9)
$digits="5"; //number of digits. leave blank to leave it only as long as it has to be
//no need to edit below
if (!isset($_SESSION)) {
session_start();
}
$page = urlencode($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'].'.counter');
if (!file_exists('counter/')) {
mkdir('counter');
}
$visits = file_exists('counter/'.$page) ? (int)file_get_contents('counter/'.$page) : 0;
if (!isset($_SESSION['counter'])) {
$visits++;
createFile('counter/'.$page,$visits);
$_SESSION['counter'] = 'counted';
}
function createFile($file,$content) {
$mode='w+';
$fp = fopen($file,$mode);
fwrite($fp,$content);
fclose($fp);
}
if ($type != "text") {
while(($digits-strlen($visits)) <0) {
$digits+=1;
}
$digits=$digits-strlen($visits);
for($i=0;$i<$digits;$i+=1) {
$img.="<img src='" . $url . "0" . $type . "' />";
}
for($n=0;$n<strlen($visits);$n+=1){
$length=str_split($visits,1);
$img.="<img src='" . $url . $length[$n] . $type . "' />";
}
} else {
$img = $visits;
}
$visits="<table border='0' align='center'>";
$visits.="<tr><td><center>Hits:</center></td></tr><tr><td>";
$visits.=$img;
$visits.="</td></tr></table>";
?>
Thanks for those amazing counters guys! One question for tech_support, how come I am getting these errors on my page? http://www.athletes4excellence.com/layout.php
tech_support
01-11-2008, 01:20 AM
You just need to create a directory called "counter", because it's not allowing you too. File permission errors. Make sure the directory has 777 permissions.
Great thanks! umm, now what do I do if I want each view counter to be different (example: each video to have different counter)
tech_support
01-11-2008, 03:44 AM
If your address bar changes the URL for each different video, you'll be fine. :)
Can I see a demo page where you put your videos? Thanks.
Well, I don't have it setup yet. So I'll be fine with each web address being different? What if all the videos are in one page? like this video page... flocasts.org/flowrestling/flowrestlr/index.php
tech_support
01-11-2008, 04:08 AM
I'd suggest putting links to the movies, and displaying them one by one.
There's no way I can do it to have it on like that page?
I really want to do and be able to do it, like this rater that I have where it automatically makes a new one when I give it a name.
Can anyone tell me why I am getting this "Warning: mkdir(counter) [function.mkdir]: Permission denied in /home/athletes/public_html/counter.php on line 8" on this page?
http://athletes4excellence.com/indexxxxx.php
Thank you.
BLiZZaRD
01-28-2008, 09:56 PM
What ever file is listed on line 8 of counter.php is not writable. CHMOD to 755 to fix it.
That seems most logical.
Thanks. However, I'm still getting the errors, http://www.athletes4excellence.com/mapper/indexxxxx.php.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.