Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: number of views script

  1. #1
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!

  2. #2
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anyone please?

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    counter.inc.php:

    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);
    }

    ?>
    Add this to the very top of your page where you want to add the counter:
    PHP Code:
    <?php include('counter.inc.php'); ?>
    And to get the visits put this where you want it:
    PHP Code:
    <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.
    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

  4. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    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.

  5. #5
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    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

  7. #7
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Great thanks! umm, now what do I do if I want each view counter to be different (example: each video to have different counter)

  8. #8
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    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

  9. #9
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  10. #10
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •