Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 25-04-2004, 11:39 AM
hafizuddin's Avatar
Novice Webmaster
 
Join Date: May 2002
Location: Klate
Posts: 91
Rep Power: 82
hafizuddin is on a distinguished road
Unhappy hit counter code

can someone out there give me an efficient hitcounter code??
my code didnt wok properly. when i keep reload the page, the number will increase. i want the user only hit the page and counted as one hit until the time is expire (let say 45 minutes).


PHP Code:
<?php
if (!isset ($_SESSION['count'])):
session_cache_expire(45);
$cCount=file_get_contents("/apih/db/counter.txt");
$cCount++;
$cPath=realpath("/apih/db/counter.txt");
$cHandle=fopen($cPath,"w");
fwrite($cHandle,$cCount);
fclose($cHandle);
$_SESSION['count']=$cCount;
endif;
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 25-04-2004, 05:40 PM
zaimlah's Avatar
Inspired Webmaster
 
Join Date: Jul 2001
Location: ttdi
Posts: 129
Rep Power: 92
zaimlah is on a distinguished road
ok, the problem with your code is you store all hit counts into a single file. you need to somehow seperate each session's (meaning each visitor's) hit count.

you can do that by storing the session id as well. here's a quick code i thought up, it might not work at all, just to give you an idea:
PHP Code:
<?php
if (!isset ($_SESSION['count'])):
session_cache_expire(45);
$counterFile file("/apih/db/counter.txt");
foreach (
$counterFile as $cLine) {
    
$cArr explode(":"$cLine);
    
$cSessid $cArr[0];
    
$cCount $cArr[1];
    if (
$cSessid == session_id()) {
        break;
    }
}
$cCount++;
$cPath=realpath("/apih/db/counter.txt");
$cHandle=fopen($cPath,"w");
fwrite($cHandle,$cCount);
fclose($cHandle);
$_SESSION['count']=$cCount;
endif;
?>
hope that helps.
__________________
blog:zaim_bakar_blog | biz:box
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 29-04-2004, 09:24 AM
Moderator
 
Join Date: Jun 2001
Location: BTHO
Posts: 750
Rep Power: 106
MENJ is on a distinguished road
Send a message via ICQ to MENJ
You might want to go to http://www.hotscripts.com to see the hit counters there in PHP...just to give you a general idea of how some of them work

- MENJ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 30-04-2004, 11:54 PM
hafizuddin's Avatar
Novice Webmaster
 
Join Date: May 2002
Location: Klate
Posts: 91
Rep Power: 82
hafizuddin is on a distinguished road
it's okay now. i had store the session id in cookie. also, my host enable the trans-id, which mean the session id can be transfer through url. with that, i can count unique visitors.

anyway, thx for the link, i will chek it out
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 13-05-2004, 01:18 AM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 769
Rep Power: 101
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
or mr google may help u too
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes 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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shoutbox n Web Counter alfirus Websites Review and Suggestion 1 26-08-2006 03:19 AM
FrontPage Extensions - Hit Counter not working for Subdomain? Cosmos75 Webmaster Tools 2 03-06-2004 12:31 AM
Adobe Photoshop CS (Counter Strike?) mysticmind Graphic Design 10 29-01-2004 04:10 PM
code displayed or3o Website Programming 7 24-01-2004 06:47 PM
It's time to code yourself. bazet Website Programming 2 21-09-2002 11:14 AM


All times are GMT +8. The time now is 02:05 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61