Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
CJ Webmaster Forums Forum Index -> PHP Scripts » CJ Hit Counter

   
A New : CJ Hitcounter , Unique Hits , Unique IP# Logging
View previous topic :: View next topic  

Rate This Version !
Satisfied
 100%  [ 1 ]
Not Satisfied{Please explain why in the forum}
 0%  [ 0 ]
Total Votes : 1

Author Message
PHPDUMMY
CJ-Design.com Moderator



Joined: 09 Mar 2005
Posts: 517
Location: South East Kentucky,U.S.A.

Posted: Thu May 12, 2005 9:59 am    Post subject: A New : CJ Hitcounter , Unique Hits , Unique IP# Logging

This version has a few options added in for the most common questions posted here in the forums.

*No MySQL , No Cookies!

Just copy and paste the code that follows and make sure you save the files as filenames shown for each code chunk.

This version requires that your Host permits you to use SuperGlobals.

Conforms to //-->Apache 2.0.53
Conforms to //-->PHP 5.0.3

FileName: counter.php

Code:

<?php
$fp = fopen($COUNT_FILE, "r+");
flock($fp, LOCK_SH);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
flock($fp,LOCK_UN);
fwrite($fp, $count, strlen($count));
fclose($fp);
?>


FileName: pagecounter.php

Code:

<?php
include 'configcount.php';
if (file_exists($COUNT_FILE)) {
  include 'counter.php';
$passage = "$count";
}
if($log_ip == true) {
if (file_exists($location_ip)) {
    $fp = fopen($location_ip,"a+");
// $_SERVER['REMOTE_ADDR'] REQUIRES THAT UR HOST PROVIDES SUPERGLOBALS
$ip = $_SERVER['REMOTE_ADDR'];
fwrite($fp,$ip,strlen($ip));
    fclose($fp);
}}
?>
<?php
if($hidden == false) {
  include 'footer.php';
} else {
 include 'nofooter.php';
}
?>


FileName : uniquecounter.php

Code:

<?php
include 'configcount.php';
$ipfound = false;
if (file_exists($location_ip)) {
if($log_ip == true) {
  $fp = fopen("$location_ip","r+");
 flock($fp, LOCK_SH);
  $buffer = fgets($fp, 4096);
$str_ip = $_SERVER['REMOTE_ADDR'];
  if(stristr($buffer, $str_ip) === FALSE) {
    flock($fp,LOCK_UN);
        fwrite($fp,$str_ip,strlen($str_ip));
$ipfound = true;
fclose($fp);
if (is_bool($ipfound == true)){
if (file_exists($COUNT_FILE)) {
$fp = fopen($COUNT_FILE, "r+");
flock($fp, LOCK_SH);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
flock($fp,LOCK_UN);
fwrite($fp, $count, strlen($count));
fclose($fp);
$passage = "$count";
}}}}}
if (is_bool($ipfound == false)){
if (file_exists($COUNT_FILE)) {
$fp = fopen($COUNT_FILE, "r+");
flock($fp, LOCK_SH);
$count = fgets($fp, 4096);
$count = $count;
fseek($fp,0);
fclose($fp);
$passage = "$count";
}}
if($hidden == false) {
  include 'footer.php';
}else {
 include 'nofooter.php';
}
?>



FileName: footer.php

Code:

<?php
echo "<html>\n";
echo "<head>\n";
echo "<title></title>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
if($sportstylesheet == true) {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$stylesheetform\">\n";
}
echo "</head>\n";
echo "<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n";
echo "<center>This page has Recieved  <b>\n";
echo "$passage</b> Visitors \n";
if($displayinstall == true) {
echo " since: $installDate \n";
}
if($checkfilesforwritepermissions == true) {
if (is_writable($COUNT_FILE)== true) {
  echo "<p>$tinystring = $COUNT_FILE is writeable</p> \n";
  }
if (is_writable($location_ip)== true) {
  echo "<p>$tinystring2 = $location_ip is writeable</p> \n";
  }
if($checkfilesforwritepermissions == true) {
if (is_writable($COUNT_FILE)== false) {
    echo "<p>$tinystring = $COUNT_FILE is Not writeable</p> \n";
    }
if (is_writable($location_ip)== false) {
    echo "<p>$tinystring2 = $location_ip is Not writeable</p> \n";
    }}}
echo "</center>\n";
echo "</body>\n";
echo "</html>\n";
?>



FileName: nofooter.php

Code:

<?php
echo "<center>\n";
echo "</center>\n";
?>


FileName: configcount.php

Code:

<?php
///////////////////////////////////
// LOG THE IP#'S ?
$log_ip = true;
//////////////////////////////////
// THE IP LOG FILE
$location_ip = "iplog.txt";
/////////////////////////////////
// DISPLAY THE INSTALL DATE ?
$displayinstall = true;
/////////////////////////////////
// INSTALL DATE
$installDate = "05-24-2005";
/////////////////////////////////
// FALSE TO SHOW THE HITS , TRUE  TO HIDE THE HITS
$hidden = false;
/////////////////////////////////
// CHECK CHMOD
$checkfilesforwritepermissions = false;
/////////////////////////////////
// THE COUNTER FILE
$COUNT_FILE = "hitcounter.txt";
/////////////////////////////////
// JUST A STRING TO USE FOR CHECKING CHMOD OF FILES
$tinystring = "";
$tinystring2 = "";
////////////////////////////////
// ADD AN .CSS STYLESHEET?
$sportstylesheet = true;
// IF .CSS IS USED , PLACE THE FILE LOCATION BELOW
$stylesheetform = "counter.css";
///////////////////////////////
// LOG UNIQUE HITS OR LOG PAGE LOADS ? SETTING THE BELOW TO TRUE WILL LOG UNIQUE
// IF THE BELOW IS MADE FALSE , THEN PAGE LOADS WILL BE LOGGED INSTEAD.
$loguniqueid = true;
$ipfound = false;
///////////////////////////////
?>


filename : hitcount.php

This is the file to call
[ Example:-->> <?php include("hitcount.php"); ?> ]
Code:

<?php
include 'configcount.php';
if ($loguniqueid == true) {
  include 'uniquecounter.php';
} else {
 include 'pagecounter.php';
}
?>


Create a text file named : " iplog.txt " . place 127.0.0.1 inside the file , close and save.
Create an text file named : " hitcounter.txt " . place a 1 ( the number 1 ) inside,close the text file and save it.

Filename : counter.css

Code:

table {
   font: 9pt "trebuchet ms", arial, sans-serif
}
body {
   color: #333333;
   background-color: #FFFFFF;
   font-family: "trebuchet ms", Arial, sans-serif;
   font-size: 9pt;
}
p {
   margin-top: 0px;
   margin-bottom: 0px;
   }



This version has not been tested for security vulnerabilities , please be advised. Please report any bugs or security enhancements you may find useful for others to apply towards this version of the CJ-Hitcounter.

Even though this script doesnt show the CJ-Copyright , it should be applied towards the use of this script , as the original version of the HitCounter here at CJ-design was the inspiration of this new version.

<-- The CJ-Hitcounter , Modified by : Danny Pryor -->


//------------------edit notes below-->

UpDated on May-13,2005 ...... Added the option to log unique Visitors.

//----------New Available Options ::

Option : Show the counter results to your visitors , or hide the results for your own viewing.
Option : The onboard ability to check that the files are CHMod as necessary.
Option : *.* .css supported
Option : You have the option of logging Unique Visitor IP#'s , or Logging Page Loads .
Option : Display the Install Date of the Counter , or use this as a greeting message .
Option : To Log The Ip#'s ? Kind of a dumb option , but you may want to temporarily turn the logging off for some reason .

Change Log : 05-24-2005 ; Repaired The Unique IP Log/Unique Counter.


Last edited by PHPDUMMY on Thu Jun 02, 2005 11:03 pm; edited 8 times in total
Back to top
darkcarnival
CJ-Design.com Moderator



Joined: 10 Jul 2003
Posts: 1222
Location: Michigan

Posted: Thu May 12, 2005 4:03 pm    Post subject:

this looks very good dude
_________________
List of Mods to James Scripts!
http://www.cj-design.com/forum/viewtopic.php?t=1798

Elite Bulletin Board, comming soon!
Back to top
Display posts from previous:   
       CJ Webmaster Forums Forum Index -> PHP Scripts » CJ Hit Counter All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
iCGstation v1.0 Template By Ray © 2003, 2004 iOptional, Mods by CJ Website Design