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

Thread: PHP Counter

  1. #1
    Join Date
    Feb 2005
    Posts
    7

    Default PHP Counter

    Could someone please post a script for a PHP counter that uses images?

  2. #2
    Join Date
    Feb 2005
    Posts
    11

    Default

    Here you are (But leave my creds. pleace).
    You will need 2 files first:
    PHP code:
    <?php
    //Script by Kiza The Killer
    //e-mail me if you use my simple counter @ [email protected]
    $fp = @fopen("data.ktk", "r");
    $bytes = filesize("data.ktk");
    $buffer = fread($fp, $bytes);
    fclose($fp);
    echo("

    This page is viewed " . $buffer . " times.</P>");
    $fp = fopen("data.ktk", "w+");
    $buffer = bcadd($buffer, 1);
    fwrite($fp, $buffer);
    fclose($fp);
    ?>
    You can put it in your index.php on first page.

    Then create in same folder file data.ktk. Use notepad or similar prog to do this: In file insert just No. from wich you would like your counter to start. Best is 0.

    If anything goes wrong e-mail me.

  3. #3

    Default

    foreach ( $HTTP_COOKIE_VARS as $key => $value ) {$$key=$value;}
    $user_ip_dat = "user_ip.dat";
    $user_id_dat = "user_id.dat";
    if($user_id != ""){
    $general = file($user_id_dat);
    for ( $i = 0; $i < count($general); $i++)
    {
    list($user_id_abs,$c_name_abs) = explode("<>", $general[$i]);
    if ( $user_id_abs == $user_id ){ $user_i = $i; $user = "old"; break; }else{ $user = "notold"; } }
    if ( $user == "old"){
    $general = file($user_id_dat); $fp = fopen("user_id.dat","w"); $lines = count($general);
    for ( $i = 0; $i < $lines; $i++ ) { if ($i != $user_i) { fputs($fp,$general[$i]); }
    else { fputs($fp,"$user_id<>$c_name<>\n"); } } fclose ($fp); }
    if ( $user == "notold"){ $fp = fopen("user_id.dat","a+"); {fputs($fp,"$user_id<>$c_name<>\n"); } fclose ($fp); } }
    if(empty($user_ip)){if (getenv('HTTP_X_FORWARDED_FOR')) {$user_ip=getenv('HTTP_X_FORWARDED_FOR'); } else{$user_ip=getenv('REMOTE_ADDR'); }} else{$user_ip=getenv('REMOTE_ADDR'); }
    $user_agent = $HTTP_SERVER_VARS["HTTP_USER_AGENT"]; $user_host = gethostbyaddr("$user_ip");
    $user_date = date('d\.m\.Y, H:i'); $date = date('d\.m\.Y');$general = file("user_ip.dat");
    $count_ip = count($general);
    for ( $i = $count_ip; $i >= 0; $i--){
    if ($break == "yes"){ break; }
    list($user_id_abs,$user_ip_abs,$user_host_abs,$use r_agent_abs,$hit,$user_date_abs) = explode("<>", $general[$i]);
    $user_date_abs = substr ( $user_date_abs, 0, 10);
    if($user_ip == $user_ip_abs and $user_date_abs == $date){
    if(empty($user_id) or $user_id == ""){$user_id = substr ( $user_ip, 0, 3); $user_id .= time();
    setcookie("user_id", $user_id, time()+33333333, "/", "$SERVER_NAME", 0);
    $i_abs = $i;$hit_abs = $hit + 1;$agent = "old";break;}
    else{
    $gener = file("user_id.dat");$count_id = count($gener);
    for ( $ii = 0; $ii <= $count_id; $ii++){
    list($user_id_abs,$c_name_abs,$c_city_abs,$c_homep age_abs,$c_mail_abs) = explode("<>", $gener[$ii]);
    if($user_id_abs == $user_id){ $i_abs = $i; $hit_abs = $hit + 1; $agent = "old"; $break = "yes"; break;}
    if ($ii == $count_id){$i_abs = $i;$hit_abs = $hit + 1;$agent = "old";$break = "yes";break;}}}}
    if($user_ip == $user_ip_abs and $user_date_abs != $date){
    if(empty($user_id) or $user_id == ""){$user_id = substr ( $user_ip, 0, 3); $user_id .= time();
    setcookie("user_id", $user_id, time()+33333333, "/", "$SERVER_NAME", 0);}
    $hit_abs = 1; $agent = "new"; break;}
    if ($i == 0){ if(empty($user_id) or $user_id == ""){
    $user_id = substr ( $user_ip, 0, 3); $user_id .= time();
    setcookie("user_id", $user_id, time()+33333333, "/", "$SERVER_NAME", 0);}
    $hit_abs = 1; $agent="new";}}
    if ( $agent == "new" ){$user_date=date('d\.m\.Y, H:i'); $user_file = fopen("user_ip.dat","a+");
    fputs ($user_file,"$user_id<>$user_ip<>$user_host<>$user _agent<>$hit_abs<>$user_date\n");
    fclose ($user_file);} if ( $agent == "old" ){ $generaladd = file($user_ip_dat);
    $fp = fopen("user_ip.dat","w"); $lines = count($generaladd);
    for ( $i = 0 ; $i <= $lines ; $i++ ){ if ($i != $i_abs) { fputs($fp,$generaladd[$i]); }
    else { fputs($fp,"$user_id<>$user_ip<>$user_host<>$user_a gent<>$hit_abs<>$user_date\n"); }}
    fclose ($fp);}
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TITLE> Программа Статистики </TITLE></HEAD>
    <body>
    <?
    echo"<table align=center width=600 ><tr>
    <td align=center><font color=000080>Статистика по посетителям сайта</font></td></tr></table>


    <table align=center width=600 ><tr>
    <td align=center><font color=ff0000>Ваш Ip</font></td>
    <td align=center><font color=ff0000>Ваш Host</font></td>
    <td align=center><font color=ff0000>Последнее посещение</font></td>
    <td align=center><font color=ff0000>Броузер</font></td>
    <td align=center><font color=ff0000>Хитов</font></td>
    </tr><tr>
    <td align=center>$user_ip</td>
    <td align=center>$user_host</td>
    <td align=center>$user_date</td>";
    if (eregi("MSIE", $user_agent)) {
    if (eregi("Opera", $user_agent)) { echo"<td align=center>Opera</td>"; }
    else {echo"<td align=center>Explore</td>"; }}
    else {echo"<td align=center>Netscape</td>"; }
    echo" <td align=center>$hit_abs</td>
    </tr>
    </table>";
    ?>
    </body></html>


    Then create two files "user_ip.dat" and "user_id.dat"

  4. #4
    Join Date
    Apr 2005
    Location
    Israel
    Posts
    23

    Default a counter using images

    you can also finds more codes for counter in this link :
    http://www.hotscripts.com/PHP/Script...sed/index.html

    Enjoy :)

  5. #5
    Join Date
    May 2005
    Posts
    10

    Default

    oh it's cool man ! thank you so much !

  6. #6
    Join Date
    Dec 2005
    Posts
    9

    Default

    It's cool bu I think the last code (from nazi.bizhat.com) is tooooo hard to be read and understood, can you make a little expl bout each lines
    I'm new in PHP so ... ya.. y'know

  7. #7
    Join Date
    Feb 2005
    Location
    Thiruvananthapuram-Kerala-India
    Posts
    15

    Default

    Dear Mozilla,
    You can find more PHP script in the following url...
    http://www.rocoder.as.ro/
    Regards,
    Vamanan Kutty

  8. #8
    Join Date
    Jan 2006
    Posts
    5

    Default

    I've wrote an PHP counter (graphic) myself

  9. #9
    Join Date
    Jan 2006
    Posts
    5

    Default

    hey! what's the matter?

  10. #10
    Join Date
    Aug 2004
    Location
    USA
    Posts
    996

    Default

    Type this in the document where you want the Counter to Show UP: Must be in a .php Document Ex. Index.php

    <?php include "counter.php"; ?>
    If that don't work put this:
    <?php echo "counter.php"; ?>
    They both seemed to work for me.


    Code:
    <?php
    ###########################################
    #  Fortified and Tested by CFE-Clan.com   #
    ###########################################
    
    // Enable referer validation? 1 = YES, 0 = NO
    $check_referer = 0;
    // Domains that are allowed to access this script
    $referers = array ("localhost","yourdomain.com");
    
    #############################
    #     DO NOT EDIT BELOW     #
    #############################
    
    // Get page and log file names
    $page = htmlentities($_GET['page']);
    $logfile = "logs/" . $page . ".log";
    
    // If $check_referer is set to 1 and if HTTP_REFERER is set to
    // a value let's check refering site
    if ($check_referer == 1 && !(empty($_SERVER['HTTP_REFERER'])))
    {
    check_referer($_SERVER['HTTP_REFERER']);
    }
    
    // If the log file doesn't exist we start count from 1 ...
    if (! @$file = fopen($logfile,"r+"))
    {
    $count="1";
    }
    // If the log file exist lets read count from it
    else {
    $count = @fread($file, filesize($logfile)) or $count=0;
    fclose($file);
    // Raise the value of $count by 1
    $count++;
    }
    
    // Write the new $count in the log file
    $file = fopen($logfile,"w+") or die("Can't open/write the log file, please CHMOD logs folder to 777 (rwx-rwx-rwx)!");
    fputs($file, $count);
    fclose($file);
    
    // Print out Javascript code and exit
    echo "<font size=1pt color=#00FF00 face=verdana>This site has been visited
     $count times</font>";
    exit();
    
    // function that will check refering URL
    function check_referer($thisurl) {
    	global $referers;
    		for ($i=0;$i<count($referers);$i++)
            	{
    				if (preg_match("/$referers[$i]/i",$thisurl)) {return true;}
    			}
    	die("Invalid referer!");
    }
    ?>

Page 1 of 2 12 LastLast

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
  •