Computing.Net > Forums > Web Development > Need Simple Hit Counter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need Simple Hit Counter

Reply to Message Icon

Name: NarrowPathPilgrim
Date: January 15, 2005 at 22:23:49 Pacific
OS: XP Home
CPU/Ram: 2.53 GH'z
Comment:

Hello, I am looking for a simple way to make a hit counter in HTML that displays the results in text format instead of using a graphic to display the results, all of the hit counters that I have seen just link you to a immage on some other server and I am looking for a way to do it without having to do that.



Sponsored Link
Ads by Google

Response Number 1
Name: NarrowPathPilgrim
Date: January 15, 2005 at 22:38:19 Pacific
Reply:

Sorry, I should have read the other posts before asking!!!


0

Response Number 2
Name: Khalid
Date: January 16, 2005 at 00:16:07 Pacific
Reply:

No problem Zach!


0

Response Number 3
Name: Laler
Date: January 17, 2005 at 05:46:37 Pacific
Reply:

hi Zach,

saw your post on the other thread then I got interested :D I did a search and here it is on the 1st result... .htaccess here is only meant to include the counter to every .html page... it has nothing to do with the counting process... you also need to have shell access to the server (I think), because you must run the installation file (and some configuration) directly...

http://www.viaverio.com/support/virtual/web/cgi/lib/counter/

basically, to create "counters" you need a server-side scripting as SN long-explained in the other thread, CGI in this case...

why not use PHP? it's less than 10 lines I think :)

^o^
are you in Asia? do you watch Animax Asia? Please Vote


0

Response Number 4
Name: cubesoft
Date: January 17, 2005 at 07:33:45 Pacific
Reply:

Try this http://www.digits.com/create.html. VERY NICE! I use this every time.

---
Tommy Segoro
CubeSoft Information Technology - Online Computer Store, Web Site Design, Software Development, Search Engine Optimization
http://www.cubesoft.com.au
info@cubesoft.com.au


0

Response Number 5
Name: NarrowPathPilgrim
Date: January 17, 2005 at 11:02:52 Pacific
Reply:

I need to use HTML for the main page but I could use PHP for another page and add some code into the HTML page to use the PHP file, Isn't that how most free hit counter services work?


0

Related Posts

See More



Response Number 6
Name: Laler
Date: January 17, 2005 at 11:24:49 Pacific
Reply:

you sure you can't use index.php ?

the whole page can be html, only the extension changed into .php

then you can add let's say in a TD on the bottom-most table

<td><?php include ("counter.php"); ?></td>

-----

if you dont want to change the index file's extension, then there're other options too:

1. make the server parse .html with PHP (pure html wont be affected) by using .htaccess

2. use IFRAME on the place where you want the counter to appear, point that IFRAME to a PHP file... you can customize IFRAME to not showing border and put the same background color on the counter(.php) file so it'll match the index.htm file...

3. use javascript to work in conjunction with PHP... so a javascript code on your HTML page will call a php file which construct javascript code to _print_ the hit counter.

^o^
are you in Asia? do you watch Animax Asia? Please Vote


0

Response Number 7
Name: NarrowPathPilgrim
Date: January 18, 2005 at 15:12:58 Pacific
Reply:

The third option would be great! That is what I was thinking of but I don't know enough JavaScript to do it.


0

Response Number 8
Name: Laler
Date: January 18, 2005 at 16:00:32 Pacific
Reply:

try this one:

create counter.php

<?php
session_start ();

// get current hit
$opFile = fopen ("counter.txt", "r");
$handle = fread ($opFile, filesize ("counter.txt"));
fclose ($opFile);

// if new session
if (!isset ($_SESSION['hit'])){

// set session
$_SESSION['hit'] = TRUE;

// add the hit
$handle = $handle + 1;

// print javascript
echo 'document.write("'.$handle.' Hits");';

// put new hit to db
$opFile = fopen ("counter.txt", "w");
fwrite ($opFile, $handle);
fclose ($opFile);

// else
}else{

// print only
echo 'document.write("'.$handle.' Hits");';
}
?>

then create counter.txt with number (let's say: 0) as its content... nothing more not even a single space (to make sure $handle + 1 won't produce error)

then on your html page, put:

<script language="JavaScript" src="counter.php" type="text/JavaScript"></script>

at the place where you want the counter to appear...

-----

I'm not really sure about this, about how will browser's javascript parser act on file extensions other than .js but I tested the above with IE & firefox and it's fine

-----

the counter above use session (same browser session wont add the count)

and dont forget to allow counter.txt to be writeable by all

^o^
are you in Asia? do you watch Animax Asia? Please Vote


0

Response Number 9
Name: Laler
Date: January 18, 2005 at 16:11:28 Pacific
Reply:

* about my 1st post above, the script is 9 lines long if we skip the php tag and dont use session :P

^o^
are you in Asia? do you watch Animax Asia? Please Vote


0

Response Number 10
Name: NarrowPathPilgrim
Date: January 19, 2005 at 10:33:16 Pacific
Reply:

Hmmm, I must be doing something wrong, it doesn't work for me, I am testing it on a windows server so the problem can't be file write permitions, Any Ideas?


0

Response Number 11
Name: Laler
Date: January 19, 2005 at 10:51:09 Pacific
Reply:

any error message? try putting

error_reporting(E_ALL);

on top of the script (before session start) and try calling it (counter.php) again from the browser, see what error comes up...

it *could* be file permission... is it in your own PC or not?

^o^
are you in Asia? do you watch Animax Asia? Please Vote


0

Response Number 12
Name: NarrowPathPilgrim
Date: January 19, 2005 at 13:09:44 Pacific
Reply:

OK, now I get this error

Line:2
Char:1
Code:0
Error:Syntax error
URL:file://C:\WM\www\hitcounter\counter.html

And Yes, it is hosted on my PC


0

Response Number 13
Name: NarrowPathPilgrim
Date: January 19, 2005 at 13:13:03 Pacific
Reply:

Sorry, it was my problem and I got it fixed, I was just running the file from the folder instead of running it thought the server. I should have known better!


0

Response Number 14
Name: NarrowPathPilgrim
Date: January 19, 2005 at 13:13:35 Pacific
Reply:

Thanks for the code!!!!!!!!!!


0

Response Number 15
Name: Laler
Date: January 19, 2005 at 21:53:28 Pacific
Reply:

np =รพ


0

Response Number 16
Name: Saucie_
Date: February 22, 2005 at 11:58:24 Pacific
Reply:

Hello,

I have tried to use the script that was posted above, however it is not working.

I created the files - counter.php, counter.txt and my test html page is countertest.htm

all files are located in the root folder of my site. This is on an intranet site if that makes a difference.

When I load the page in the browser (off the test server), I am getting the same error code -

Line:2
Char:1
Code:0
Error:Syntax error
URL:http://test/countertest.htm

The counter.txt file is set to writable. I don't know why it is not working. Any help would be appreciated. Thanks.


0

Response Number 17
Name: Laler
Date: February 22, 2005 at 13:20:41 Pacific
Reply:

hi,

you sure the webserver will run PHP correctly?

maybe by testing it to run a simple php file:

<?php
echo 'hello world';
?>

save the above as test.php and try calling http://localhost/test.php

I'm not really sure where did that error message refer to... what's in Line 2 of the file countertest.htm?

what's showing when you call counter.php? (http://localhost/counter.php)

it should be:

document.write("some Hits");

ps:
the script is meant for html pages to fetch the counter by using javascript, which is created by PHP... so if you can put php directly to your "html" pages (by changing .htm into .php), you can use another more simple way.

---
siggy space for rent


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Need Simple Hit Counter

Help! Quick! I need a Hit-Counter.. www.computing.net/answers/webdevel/help-quick-i-need-a-hitcounter/808.html

FREE Hit Counter www.computing.net/answers/webdevel/free-hit-counter/1290.html

Hit Counter www.computing.net/answers/webdevel/hit-counter/2347.html