Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hit counter with php?

Posted on 2011-02-19
18
Medium Priority
?
329 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
ID: 34935968
Nothing here you could use?
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 34935972
Could this be what you are looking for?  http://www.developingwebs.net/phpclass/hitcounter.php
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34936015
@YoderCM Second link on my suggestion
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:MOSTAGHASSI
ID: 34936098
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 2000 total points
ID: 34936123
It is How many bytes to read in one go.
http://php.net/manual/en/function.fread.php
0
 

Author Comment

by:MOSTAGHASSI
ID: 34936157
@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
ID: 34936195
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
ID: 34936207
Try adding this to the top of the script

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

Author Comment

by:MOSTAGHASSI
ID: 34936713
No,i test it locally.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34936727
Is the file writeable by the server? (permissions)
0
 

Author Comment

by:MOSTAGHASSI
ID: 34936737
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
ID: 34936777
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
ID: 34936779
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
ID: 34936785
That is how to include the counter on a page you want to count the loading of
0
 

Author Comment

by:MOSTAGHASSI
ID: 34936791
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
ID: 34936963
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
ID: 34937077
thanks
0
 
LVL 75

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

971 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