Follow us on Twitter!
One mans freedom fighter, another's terrorist.
Friday, April 18, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 23
Guests Online: 22
Members Online: 1

Registered Members: 82826
Newest Member: Jakob
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

trouble with a hit counter


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-07-06 09:51
here is the code:

Code

<?php
$filename = "hits.html" ;
$startdate = "July 2006" ;
$ip = getenv("REMOTE_ADDR") ;
$currentip = "$ip";
$file = file($filename);
$file = array_unique($file);
 
$file = "$filename";
$fd = fopen ($file, "r");
$fget= fread ($fd, filesize ($file));
fclose ($fd);
$totalips = htmlspecialchars($fget);
if (preg_match ("/$ip/i", "$totalips"))
{$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo "Visitors since,<br />";
echo "$startdate: 000$hits";} 
else
{
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring.$currentip."<br />";
$fout= fwrite ($fd , $fcounted);
fclose($fd);
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo "Visitors since,<br />";
echo "$startdate: $hits";
}

?>





the problem im haveing is, that it logs the ip number 1 on the same line as ip number 2, so it only gets read it as 1ip. is there a way to make it split up the ip's on to diffrent lines? ive tryed /n, but that didnt seem to work :( any suggestions would help.




Edited by on 21-07-06 17:39
Author

RE: trouble with a hit counter


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-08-06 15:47
this is the coding i use for a hit counter ;)

btw disable smilies lol

save this as counter.php:

Code

  <?php
     
   $count='count.txt';
   
      if (file_exists($count))
         {
            $var=fopen($count,'r+');
            $visits=fread($var,filesize($count));
            rewind($var);
            $visits++;
            fwrite($var,$visits);
            fclose($var);
         }
      else   
         {
            echo 'N/A';
            Die();
         }
         
      $num=sprintf("%s",$visits);
      print $num;
      
  ?>





now in the page which u want the hits to be displayed add this code (where u want the text to be):

Code

<?php include('counter.php') ?>





and in tht directory make a new textfile called count.txt, and set the text to 0

hope this helps ya man