Jump to content
Sign in to follow this  
joshg678

Php Hit Counter

Recommended Posts

Not the best, but a little something i made for you all :love:

First create your a text file named "count.txt" and put the number 0 in it, then save it.

Upload it and chmod is at 0666

Next open a text editor, and create a file called count.php and put the following code in:

<?php

// Copyright (c) Josh Gould 

$COUNT_FILE = "count.txt"; // File DB that holds ur amount of hits 

if (file_exists($COUNT_FILE)) { 

 ? $fp = fopen("$COUNT_FILE", "r+"); 

 ? flock($fp, 1); ?

 ? $count = fgets($fp, 4096); ?

 ? $count += 1; ?// Adds one count to file for hits 

 ? fseek($fp,0); ?

 ? fputs($fp, $count); ?

 ? flock($fp, 3); ?

 ? fclose($fp); ?

 ? echo "Hits: <b>"; 

 ? include "$COUNT_FILE"; 

 ? echo "</b><!-- hit counter by Josh Gould at http://scripts.joshrcc.com -->"; 

} else { 

 ? echo "Can't find file, check '\$file'<BR>"; // Error message 

} 

?>
Then when ever you want to count people's hits, just use this code:
<?php

include 'count.php';

?>

Share this post


Link to post
Share on other sites

its very simple, however you will have to use php files instead of html files.

Example on how to include files using php

<?php

include "files.html";

?>

When you go to include the files, it can be any type of file, but where you put the script above has to be in a php file for it to work.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×