Hello, I am looking for a script that shows the number of views for a picture, video and etc. Please and thank you!
Hello, I am looking for a script that shows the number of views for a picture, video and etc. Please and thank you!
Anyone please?
counter.inc.php:
Add this to the very top of your page where you want to add the counter:PHP Code:<?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);
}
?>
And to get the visits put this where you want it:PHP Code:<?php include('counter.inc.php'); ?>
One visit is counted per browser session, aka. when you open your browser and visit that page it's a visit.PHP Code:<p><?php echo $visits; ?> visits.</p>
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
Edit: 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.)
Edit: 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 Code:<?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>";
?>
Last edited by Master_script_maker; 01-09-2008 at 01:45 AM.
[Jasme Library (Javascript Motion Effects)] My Site
/\/\@§†ê® §©®¡þ† /\/\@|{ê®
There are 10 kinds of people in the world, those that understand binary and those that don't.
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
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.
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
Great thanks! umm, now what do I do if I want each view counter to be different (example: each video to have different counter)
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.
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
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
I'd suggest putting links to the movies, and displaying them one by one.
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
Bookmarks