Jump to content
xisto Community
Sign in to follow this  
iGuest

A Simple Hit Counter

Recommended Posts

A Simple hit counter

1.) Open your website in Notepad or watever u use .. and where you want the counter to be put in this code:

<?php= "count.dat";if(!(Resource id #4 = fopen(,"r"))) die ("cannot open counter file");= (int) fread(Resource id #4, 20);fclose(Resource id #4);++;echo "Hits: ";Resource id #4 = fopen(, "w");fwrite(Resource id #4 , );fclose(Resource id #4);?>

2.) Now all thats left to do is make count.dat file and upload to your server and CHMOD to 777 Your done.
Make Sure count.dat file is in same directory as where counter is being shown.


:wink:

Share this post


Link to post
Share on other sites

What language is this in?

It starts with <?php so its PHP language. Its simple, not too long and nice. The shorter the better if the desired output is the same. In this case I like this script. Well done..

Share this post


Link to post
Share on other sites

Well, yes, but that's not PHP. It looks like he took it out of a psuedo-code example and added a <?php tag to the beginning. He has assignment operators with nothing to assign the results to, invalid resource identifiers, and missing arguments.

Share this post


Link to post
Share on other sites

Will you please explain to me how this could posibly work. These are your mistakes:

You have an assignment operator without anything to assign the result to-Lines 2 and 4

You have several references to Resource id #4. This is nowhere near correct PHP. Lines 2,3,4,7,8 and 9.

You have missing arguments in some of the functions-Lines 3, 8, and 9

You have an increment operator without any variable to increment-Line 6

You display "Hits: ", but not the number of hits.

 

This is the correct code re-written:

<?php $file = "count.dat"; if(!($file = fopen($file,"r"))) die ("cannot open counter file"); $num = (int) fread($file, 20); fclose($file); $num++; echo "Hits: $num"; $file = fopen($file, "w"); fwrite($file,$num); fclose($file); ?>

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  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.