Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-18-2008, 06:13 AM   PM User | #1
IFeelYourPain
Regular Coder

 
Join Date: Sep 2007
Posts: 250
Thanks: 19
Thanked 0 Times in 0 Posts
IFeelYourPain has a little shameless behaviour in the past
Hit Counter Resetting

I have a simple hit counter, but for some reason it resets itself every now and then. Here is the counter:

Code:
<?php
$visits = ("hits.txt");
$hits = file($visits);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>
IFeelYourPain is offline   Reply With Quote
Old 07-18-2008, 06:31 AM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
PHP Code:
<?php
$visits 
"hits.txt";
// open the file and read how many visitors was
$fp fopen($visits,"r");
$hits = (int )fgets($fp);
fclose($fp);
// increment the number of visitors
$hits++;
// open the file and write how many visitors are now
$fp fopen($visits,"w");
fputs($fp,$hits);
fclose($fp);
?>
could be done with a single fopen/fclose but how is now you can see more clear how to do each step.

regards
oesxyl is offline   Reply With Quote
Old 07-18-2008, 07:34 AM   PM User | #3
IFeelYourPain
Regular Coder

 
Join Date: Sep 2007
Posts: 250
Thanks: 19
Thanked 0 Times in 0 Posts
IFeelYourPain has a little shameless behaviour in the past
Didn't work dude. I think you forgot an echo, but not sure?
IFeelYourPain is offline   Reply With Quote
Old 07-18-2008, 07:39 AM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by IFeelYourPain View Post
Didn't work dude. I think you forgot an echo, but not sure?
it work dude. and you don't need any echo. this do exactly what your previous code indend to do.

showing the number of visitors in your page is another problem, isn't it? for that just echo $hits where you want.

regards
oesxyl is offline   Reply With Quote
Old 07-18-2008, 07:50 AM   PM User | #5
IFeelYourPain
Regular Coder

 
Join Date: Sep 2007
Posts: 250
Thanks: 19
Thanked 0 Times in 0 Posts
IFeelYourPain has a little shameless behaviour in the past
Quote:
Originally Posted by oesxyl View Post
it work dude. and you don't need any echo. this do exactly what your previous code indend to do.

showing the number of visitors in your page is another problem, isn't it? for that just echo $hits where you want.

regards
I tried the exact script you posted up there and nothing happened.
IFeelYourPain is offline   Reply With Quote
Old 07-18-2008, 08:04 AM   PM User | #6
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by IFeelYourPain View Post
I tried the exact script you posted up there and nothing happened.
post a link to the page.

regards
oesxyl is offline   Reply With Quote
Old 08-22-2008, 05:43 PM   PM User | #7
IFeelYourPain
Regular Coder

 
Join Date: Sep 2007
Posts: 250
Thanks: 19
Thanked 0 Times in 0 Posts
IFeelYourPain has a little shameless behaviour in the past
Quote:
Originally Posted by oesxyl View Post
post a link to the page.

regards
Your script did not work at all. I tried it in a regular php page on my server. I found another script and will see how it works out.
IFeelYourPain is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:28 PM.


Advertisement
Log in to turn off these ads.