Solved

Hit counter with php?

Posted on 2011-02-19
18
309 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:MOSTAGHASSI
  • 10
  • 7
18 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Nothing here you could use?
0
 
LVL 27

Expert Comment

by:yodercm
Comment Utility
Could this be what you are looking for?  http://www.developingwebs.net/phpclass/hitcounter.php
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
@YoderCM Second link on my suggestion
0
 

Author Comment

by:MOSTAGHASSI
Comment Utility
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
It is How many bytes to read in one go.
http://php.net/manual/en/function.fread.php
0
 

Author Comment

by:MOSTAGHASSI
Comment Utility
@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
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Do you have a url? Perhaps we need to keep it out of cache. Do you have any cache headers in the php?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Try adding this to the top of the script

header('Cache-Control: no-cache');
header('Pragma: no-cache');
0
 

Author Comment

by:MOSTAGHASSI
Comment Utility
No,i test it locally.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Is the file writeable by the server? (permissions)
0
 

Author Comment

by:MOSTAGHASSI
Comment Utility
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
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
 

Author Comment

by:MOSTAGHASSI
Comment Utility
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
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
That is how to include the counter on a page you want to count the loading of
0
 

Author Comment

by:MOSTAGHASSI
Comment Utility
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
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
 

Author Closing Comment

by:MOSTAGHASSI
Comment Utility
thanks
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
So you made it work? What precisely did you do to fix it?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now