is there a basic page counter script out there?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clickhappy
    Confirmed User
    • Mar 2004
    • 4027

    #1

    is there a basic page counter script out there?

    just a basic counter that tells me how many times a page is loaded?

    I dont want a sex counter, just a basic barebones counter.
    Theres got to be an easy way to do it with php, but when i look at counter scripts out there they have features and all these includes that i cant figure out how to install.
  • Kapitan Ivanov II
    Confirmed User
    • Jan 2005
    • 763

    #2
    php.net

    LEARN IT, or you'll never make it in the biz.
    Ivanov - The Original Russian Board Guy

    Comment

    • celebx
      Confirmed User
      • Jul 2001
      • 197

      #3
      PHP Code:
      <?php
      
      // SNT's Array2Txt Functions :)
      function Array2Txt($array,$fill='',$tab=1,$compress=0) { 
          if (!$fill) { 
              $txt_return='array('; 
          } 
          $n=rand(); 
          $run[$n]=0; 
          for($i=0;$i<$tab;$i++) {$t.="\t";} 
          foreach ($array as $key => $value) { 
              if (!$run[$n]) { 
                  $c=''; 
              } else { 
                  $c=', '; 
              }$run[$n]++; 
              if (is_array($value)) { 
                  $txt_return.=$c."\n".$t.'''.$key.'' => array('.Array2Txt($value,'',1,$tab+1); 
                  continue 1; 
              } 
              $txt_return.=$c."\n".$t.'''.$key.'' => ''.$value.'''; 
          } 
          if (!$fill) { 
              $txt_return.=');'; 
          } else { 
              $txt_return.=')'; 
          }     
          if ($compress) { 
              return gzcompress($txt_return, 9); 
          } else { 
              return $txt_return; 
          } 
      } 
      
      function Txt2Array($arraytxt,$decompress=0) { 
          if ($decompress) { 
              eval('$return_array = '.gzuncompress($arraytxt)); 
              return $return_array; 
          } else { 
              eval('$return_array = '.$arraytxt); 
              return $return_array; 
          } 
      }
      
      //register user and count pageviews per page
      session_start();
      if (!isset($_SESSION['count'])) {
         $new_visitor=1;
         $_SESSION['visitor'] = array();
         $_SESSION['visitor'][$_SERVER["PHP_SELF"]]=1;
      } else {
         $_SESSION['visitor'][$_SERVER["PHP_SELF"]]++;
      }
      
      //create counter data array from counter data file
      if (file_exists($counter_data_file)) {
      $counter_data = Txt2Array(file_get_contents($counter_data_file));
      } else { // create counter data file (if not exist)
         if (!$handle = fopen($counter_data_file, 'a')) {
               print "Can not create counter data file.";
               exit;
         }
         print "<!--- New Counter Data File created on ".date("r").". ---/>";
         fclose($handle);
      } 
      
      $counter_data[$_SERVER["PHP_SELF"]]["views"]++;
      if ($new_visitor) {
      $counter_data[$_SERVER["PHP_SELF"]]["visitors"]++;
      }
      
      if (is_writable($counter_data_file)) {
         if (!$handle = fopen($counter_data_file, 'a')) {
               print "Can not open counter data file.";
               exit;
         }
         $counter_data_txt = Array2Txt($counter_data);
         if (!fwrite($handle, $counter_data_txt)) {
             print "Can not write to counter data file.";
             exit;
         }
      
         print "<!--- Successfully updated counter data file, this page has been visited ".$counter_data[$_SERVER["PHP_SELF"]]["views"]." times. ---/>"; 
         fclose($handle);
      } else {
         print "The counter data file is not writeable.";
      }
      
      /*
      The Array2Txt using the compression functions and a MySQL DB for data storage enables storage of detailed per visitor traffic information for 1m+/day trafficed sites! It will enable you to create the easyest and fastest accessable, processless and optimum source of traffic information.
      */
      
      ?>
      p.s. this code has not been tested
      Last edited by celebx; 01-16-2005, 07:30 AM.
      Message me for more info: ICQ 8322641 (@gmail.com).

      Comment

      • celebx
        Confirmed User
        • Jul 2001
        • 197

        #4
        the tested code:

        http://www.phpbuilder.com/board/show...3#post10584993

        If you run TheHun.com and would like to know every detail about your visitors over an unlimited period, use this counter for maximum possibilities and performance.
        Message me for more info: ICQ 8322641 (@gmail.com).

        Comment

        • clickhappy
          Confirmed User
          • Mar 2004
          • 4027

          #5
          Originally posted by celebx
          the tested code:

          http://www.phpbuilder.com/board/show...3#post10584993

          If you run TheHun.com and would like to know every detail about your visitors over an unlimited period, use this counter for maximum possibilities and performance.

          can it be done without a database?

          Comment

          • TheMob
            Confirmed User
            • Jan 2003
            • 8584

            #6
            I love statcounter.

            Really.

            www.statcounter.com

            Comment

            Working...