+ Reply to Thread
Results 1 to 3 of 3

Thread: How To Make A Hit Counter

  1. #1
    Ryan56 is offline Member Ryan56 is on a distinguished road
    Join Date
    Aug 2006
    Posts
    58

    Default How To Make A Hit Counter

    This simple script creates an image that can be used on any page to display a hit counter. A session variable is used to ensure that the counter only advances once per browser session. In your html, put an <img> tag for the image, such as this one
    PHP Code:
    <img src="counter.php" alt="" style"border-style:inset; border-width: 3; left: 20; top: 20; position: absolute;"
    2) Now make a new file name "counter.php" without the " " in the directory where your site is.

    3)edit the counter.php file

    4) put the following code in it

    PHP Code:
    <?php
    session_start
    ();
    if (!
    session_is_registered('hit_cnt_entry')) {
    session_register('hit_cnt_entry');
    $hit_cnt_entry "0";
    } else {
    $hit_cnt_entry "1";
    }

    $filename 'counter.dat';

    if (
    is_writable($filename)) {

    $handle fopen($filename,"r");
    $count fread($handlefilesize ($filename));
    fclose($handle);

    if (
    $hit_cnt_entry == "0") {
    $handle fopen($filename,"w");
    $count $count 1;
    fwrite($handle,"$count");
    fclose($handle);
    }

    $width = (strlen($count) * 8) + 8;

    $im = @imagecreate ($width18);
    $background_color imagecolorallocate ($im255255255);
    $text_color imagecolorallocate ($im000);
    imagestring ($im442$count$text_color);
    imagepng ($im);
    imagedestroy($im);

    }
    ?>
    the counter value in stored in a different file so

    5) open notepad and put a number in it for example "100" this will be the number of hit that will be shown on the counter.

    6) name the file counter.dat and upload it to the name directory where you created the counter.php file

    and that's it your finished

    You can cheat at any time just by changing the number in the counter.dat with notepad. i have also attached the counter.php and the counter.dat file ina zip


    here is my finished file http://www.gmgraphics.profusehost.ne...ter/index.html

  2. #2
    spoweb is offline Member spoweb is on a distinguished road
    Join Date
    Nov 2007
    Posts
    51

    Default

    I made it in the file manager, but I placed in the "body" tags. There's an x where the image should be. What can I do to make the image appear? Should I take out ALL of the HTML code that was in there to begin with and leave it as a pure PHP file?

  3. #3
    bokepwap is offline Junior Member bokepwap is on a distinguished road
    Join Date
    Jun 2008
    Posts
    14

    Default

    this is simple php counter visitor,
    this code make a counter per days
    PHP Code:
        <?php
        $fn 
    "counter.txt";
        
    $fp fopen($fn"a+");
        
    $fs filesize($fn);
        
    $tdy date("d/m/y");
        if (
    $fs==0)
        {
        
    $co 1;
        
    fwrite($fp$tdy."-".$co);
        }else{
        
    $info fread($fp$fs);
        
    $cdata explode("-"$info);
        
    ftruncate($fp0);
        if(
    $tdy==$cdata[0])
        {
        
    $co $cdata[1]+1;
        
    fwrite($fp$tdy."-".$co);
        }else{
        
    $co 1;
        
    fwrite($fp$tdy."-".$co);
        }
        }
        
    fclose($fp);
        
    ?>

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 01-21-2010, 06:54 PM
  2. Scripting for CSS Counter Strike Source?
    By Jacob in forum HTML/CSS/DHTML
    Replies: 0
    Last Post: 12-25-2009, 09:21 PM
  3. How to make your counter-strike server better!
    By vsnfsn in forum General Discussions
    Replies: 1
    Last Post: 09-09-2007, 11:15 AM
  4. Steam and Counter-Strike
    By cooper in forum General Discussions
    Replies: 4
    Last Post: 03-29-2007, 08:45 PM
  5. Counter Strike?
    By BOoBOo in forum General Discussions
    Replies: 18
    Last Post: 03-15-2007, 01:16 PM

Posting Permissions

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