It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Invisible Counter

Moderator: Malcolm

Invisible Counter

Postby joshcxa on Thu Jul 21, 2005 3:18 am

How would I make an Invisible counter?
Can I make it so that it counts the hits on the home page and displays the hits on another page like hits.htm for example.

I also want to add where the viewer came from. Any help would be great.
joshcxa
DEVPPL Lightwave Moderator
User avatar
joshcxa
100+ Club
 
Posts: 156
Joined: Wed Aug 18, 2004 10:59 am
Location: Australia

Postby webmaster on Thu Jul 21, 2005 8:12 am

The absolute most simple counter a a hitcounter that uses .txt files for saving data. Everytime a page gets shows where this counter-script is included the amount in the textfile increases by 1.

[php]<?php

$filename = "counters/countername.txt";

$fp=fopen($filename,"r");
$count=fgets($fp,1024);
fclose($fp);
$fw=fopen("$filename","w");
$cnew=$count+1;
$countnew=fputs($fw,$count+1);
fclose($fw);

?>[/php]

To show the pageviews on another page, you can use this script:
[php]<?php

$filename = "counters/countername.txt";

$fp=fopen($filename,"r");
$count=fgets($fp,1024);
fclose($fp);
echo "Total Pageviews: <b>$count</b>";

?>[/php]
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby joshcxa on Thu Jul 21, 2005 12:21 pm

no joy
joshcxa
DEVPPL Lightwave Moderator
User avatar
joshcxa
100+ Club
 
Posts: 156
Joined: Wed Aug 18, 2004 10:59 am
Location: Australia

Postby Phate on Sat Jul 23, 2005 12:05 am

coudlnt you just open up the .txt file to see the number of hits?
Web-Developing since '03
Image
User avatar
Phate
500+ Club
 
Posts: 826
Joined: Sun Nov 21, 2004 4:12 am
Location: 127.0.0.1

Postby webmaster on Sat Jul 23, 2005 12:08 am

But I guess he wants to do it online, another way is to use get_file_contents(filename);
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby joshcxa on Mon Jul 25, 2005 2:53 pm

yeah clients want to be able to see the hits online but on a seperate page.

how come the script u gave me doesn't work?
joshcxa
DEVPPL Lightwave Moderator
User avatar
joshcxa
100+ Club
 
Posts: 156
Joined: Wed Aug 18, 2004 10:59 am
Location: Australia

Postby Malcolm on Tue Jul 26, 2005 2:01 am

Try
Code: Select all
<?php

$filename = "counters/countername.txt";

if(!is_file($filename)){
touch($filename);
}

$fp=fopen($filename,"r");
$count=fgets($fp,1024);
fclose($fp);
$fw=fopen("$filename","w");
$cnew=$count+1;
$countnew=fputs($fw,$count+1);
fclose($fw);

?>
Image
User avatar
Malcolm
100+ Club
 
Posts: 198
Joined: Thu Oct 07, 2004 9:53 pm
Location: Ontario, Canada

Postby joshcxa on Wed Jul 27, 2005 12:19 pm

all under control
joshcxa
DEVPPL Lightwave Moderator
User avatar
joshcxa
100+ Club
 
Posts: 156
Joined: Wed Aug 18, 2004 10:59 am
Location: Australia


Who is online

Users browsing this forum: No registered users and 0 guests