Classy Counters

Permabanned
Joined
22 Apr 2007
Posts
1,805
Ok, I know I know, but my client WANTS a web counter at the bottom of his index page and I want it to look classy and in line with the rest of the site. Not some huge lime green rotating fruit machine.

Is there a way to actually code it, or am I confined to 'downloading' a free one.

Ta
 
should be an easy enough, just do an include of a php script that increments a number in a file somewhere and display the number, shouldn't be hard
 
first google result for "php hit counter".

http://www.developingwebs.net/phpclass/hitcounter.php

Code:
<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>

i tested it and it works fine. :)

edit: i hope you've got php, this was more of a repsonse to the previous post.
 
Last edited:
Umm thanks but I'm a php newb really

I've uploaded two files to my directory

counter.php with the script and hitcounter.txt

and i've included

Code:
<?php
include ("counter.php");
?>

In the < head > of my site.

Doesnt seem to work :(
 
Ok, moved to withing <body> at the top

still, when I open or download hitcounter.txt, it's empty

Does it matter that my site is built entirely in HTML?

I do have a php through my web host though
 
well the file needs a .php extension to be parsed as php (otherwise the php include function won't work). but of course the php page can contain normal html. :)
 
well the file needs a .php extension to be parsed as php (otherwise the php include function won't work). but of course the php page can contain normal html. :)

Ok, so now I have index.php but still nothing appears in hitcounter.txt

:(

Am I missing a trick here?
 
Oh, now I get this at the top of the page

Warning: fopen(hitcounter.txt) [function.fopen]: failed to open stream: Permission denied in /home/mark1e/public_html/langham/counter.php on line 5

Warning: fputs(): supplied argument is not a valid stream resource in /home/mark1e/public_html/langham/counter.php on line 6

Warning: fclose(): supplied argument is not a valid stream resource in /home/mark1e/public_html/langham/counter.php on line 7
1

I've also changed the file attributes for counter.php but still the same error

EDIT:

OK, altered the file permissions of hitcounter.txt too and now it works, BUT, the count appears in the top left hand corner of the homepage
 
EDIT:

OK, altered the file permissions of hitcounter.txt too and now it works, BUT, the count appears in the top left hand corner of the homepage

well you need to place the include wherever you want it to be in your html. you can open/close php tags anywhere in the html. in a div/table/wherever.... it's upto you.
 
well you need to place the include wherever you want it to be in your html. you can open/close php tags anywhere in the html. in a div/table/wherever.... it's upto you.

I thought the point was that it wrote to a file that could be viewed but didnt appear on the website?
 
I thought the point was that it wrote to a file that could be viewed but didnt appear on the website?

now i'm -> :confused: what are you on about? :p

the script itself updates the text file with every hit. it also outputs the count as html to the screen (see the echo command). treat this number as content and place it wherever you want it to appear in the page.
 
now i'm -> :confused: what are you on about? :p

the script itself updates the text file with every hit. it also outputs the count as html to the screen (see the echo command). treat this number as content and place it wherever you want it to appear in the page.

No its cool. I just wanted it hidden from view as I think they look nasty, but I've stuck it subtly in the footer and all is well.

Thanks again ;)
 
No its cool. I just wanted it hidden from view as I think they look nasty, but I've stuck it subtly in the footer and all is well.

Thanks again ;)

If you don't want it to display anything just take out the echo $hits[0]; line.
 
If it's just so you can get an idea of usage, sign up for a free Google Analytics account, you get a lot more information than just how many hits your site has had.
 
If it's just so you can get an idea of usage, sign up for a free Google Analytics account, you get a lot more information than just how many hits your site has had.

I'd agree with this. I signed up the other day and it's great. Granted I have had only about 30 visits in the last week, but hey at least I know :p
 
Clocking about 1.5 - 2 mil pageviews / 250 - 300k unique visits a month here, but I know there are some people on the forum with probably a lot more than that.
 
Back
Top Bottom