Forum Moderators: coopster

Message Too Old, No Replies

PHP + index.html

         

Torniojaws

11:20 pm on Feb 14, 2004 (gmt 0)

10+ Year Member



Err, just ran into this weird one. How can I add a PHP visitor counter to my single file main page (index.html) without using frames (like I have done before).

mep00

11:01 am on Feb 15, 2004 (gmt 0)

10+ Year Member



In part it depends if the counter is text or graphics.

In either case, when your page is accessed it ups the counter by one. The counter could be stored in a text file.

With a text counter, simply echo the variable in the correct place.

With a graphical counter you'll need something like

<img src="counter.php" />
. php can genrate graphics on the fly without a problem; just remember to set the mime type in youe http headers.

I would recommend not having counter.php update the counter value, but just read it. That way you'll even count those who have graphics turned off. It's possible for two people to access the index.php brfore either of them accesses counter.php, in which case the counter will get updated twice and both users would show the same value. A very minor glitch with a simple solution:

<img src="counter.php?num=<?php echo $var;?>" />

somerset

12:36 pm on Feb 15, 2004 (gmt 0)

10+ Year Member



Torniojaws

Try this - as long as your web space is OK with server side includes (SSI).

Simply call up the php script from the SSI. I have used this successfully many times, it enables you to add a php 'island' within a html page.

Example:

<!--#include virtual="myphpscript.php" -->

If you ae not SSI enabled, you may need to amend the htaccess file.