php hit counter without database

how to make a simple php hit counter without database?



php hit counter without database
this php code is very simple.but this hit counter will hit count 100% accurately.just copy paste and see the output



<!--php 
if(!file_exists('hit_counter.txt')){
file_put_contents("hit_counter.txt",1);
}else{
$current=file_get_contents("hit_counter.txt");
file_put_contents("hit_counter.txt",$current+1);
}
  
?-->


now view hit_counter.txt text file to see total hits.you can direct access text file from a web browser. yourdomain.com/path to hit_counter.txt

record visited user data without database



this php code record all visited user data. its a different php code. no need above code.

<!--php 
$data=[];
$data['ip']=$_SERVER['REMOTE_ADDR']; //add user ip to record
$data['time']=date('y/m/d h:i:s'); //add time to record
$data['page']=urldecode($_SERVER['REQUEST_URI']); //add user loaded page to record
/**remove or add new data to above $data array**/

$datagroup='';
foreach($data as $key=-->$val){
$datagroup.='|'.$key.':'.$val;
}
file_put_contents("visitor_data.txt",$datagroup."\n", FILE_APPEND);

  
?>


now view visitor_data.txt text file to see visitor data.

No comments:

Post a Comment