Hit counter with php?

Hi all;

I want that make a hit counter for a site so each hit on a page or refresh of that page count ,but not writting in db ,is it possible that this counting do in a file and i also want that each time i reflect the last count on page.

thanks
MOSTAGHASSIAsked:
Who is Participating?
 
Michel PlungjanIT ExpertCommented:
It is How many bytes to read in one go.
http://php.net/manual/en/function.fread.php
0
 
Michel PlungjanIT ExpertCommented:
Nothing here you could use?
0
 
Cornelia YoderArtistCommented:
Could this be what you are looking for?  http://www.developingwebs.net/phpclass/hitcounter.php
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Michel PlungjanIT ExpertCommented:
@YoderCM Second link on my suggestion
0
 
MOSTAGHASSIAuthor Commented:
Thanks for all comments.

Yes, in this link i found but please let me know that what is  1024 in this line:

http://www.totallyphp.co.uk/scripts/text_file_hit_counter.htm

$count = fread($fp, 1024);
0
 
MOSTAGHASSIAuthor Commented:
@mplungjan
I have done it as discribed on that codes but the output is 1 and with any refresh of page it doesn't change,in addition when i open the counterlog.txt i see that nothing has written inside it.
0
 
Michel PlungjanIT ExpertCommented:
Do you have a url? Perhaps we need to keep it out of cache. Do you have any cache headers in the php?
0
 
Michel PlungjanIT ExpertCommented:
Try adding this to the top of the script

header('Cache-Control: no-cache');
header('Pragma: no-cache');
0
 
MOSTAGHASSIAuthor Commented:
No,i test it locally.
0
 
Michel PlungjanIT ExpertCommented:
Is the file writeable by the server? (permissions)
0
 
MOSTAGHASSIAuthor Commented:
I added :
header('Cache-Control: no-cache');
header('Pragma: no-cache');

but it is still like before,ofcourse it is clear because i test on my pc, and these codes is for working online.
0
 
Michel PlungjanIT ExpertCommented:
Php normally needs to run on a server. How do you test the php? Localhost? If so, i think you still need to avoid caching.
0
 
MOSTAGHASSIAuthor Commented:
IN the comment above the codes there is this line

 * <?php include "text_file_hit_counter.php"; ?>

do i must include this file to my page?
0
 
Michel PlungjanIT ExpertCommented:
That is how to include the counter on a page you want to count the loading of
0
 
MOSTAGHASSIAuthor Commented:
Yes, i work on  Localhost and i have lot of codes in php and work good, i added the codes:
header('Cache-Control: no-cache');
header('Pragma: no-cache');

but still not work.
0
 
Michel PlungjanIT ExpertCommented:
Then it is permissons. Try writing the file in another folder and give it correct permissions. I do not know where you are running now but I know how to do it on my server
0
 
MOSTAGHASSIAuthor Commented:
thanks
0
 
Michel PlungjanIT ExpertCommented:
So you made it work? What precisely did you do to fix it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.