PHP hit counter does not work

Greetings from Pennsylvania,

I have for some time been working on a test web site to add a hit/visitor
counter using PHP to no avail. I am hoping someone would look at my efforts and suggest what to try next.

The url is: [http://bobbear.netfirms.com/PHPTestWebSite2/PHPTestWebSite.shtml]

If you right click on the web page and select ‘view page source’ you can
see my current efforts. It includes the counter.php code also.

I understand if "#echo var=“DATE_LOCAL” runs that implies that SSI is enabled. It works on my site as you can see date and time.

The [Display Counts Button] executes the PHP code okay; but that is after the fact of course.

For the files permissions: counter.php 755 hitcount.txt 766 the SHTML file 744.

For the .htaccess file:

Currently selected directory: public_html
Edit Your .htaccess File

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

Any help would appreciated!

Since your various attempts to include php code are just displaying in the browser, it means that the php engine is not parsing your page. The most likely reason is that the file name suffix is “shtml” and not “php”. Are you actually needing server side includes, or is that just part of an experiment? I’d rename the file to PHPTestWebSite.php and try again, then go from there.

I don’t think you can’t have both SSI and PHP in the same file. Each requires a separate pass of the code, so it would make it rather slow. I suggest you do your date echo in PHP and as @tracknut says, rename your file with a .php extension. (Edited)

Check to see if the website’s hit counter’s PHP code is correct and correctly implemented.

Verify that the file that contains the hit counter data has the appropriate file permissions set. The PHP script needs to be able to write to the file.

Ensure that the code for the hit counter is compatible with the PHP version being used. Certain functions used in the code may not work with some older versions of PHP.

Check to see if any required PHP modules are installed on the server and are active.

Verify the server logs and PHP error logs for any errors that might be connected to the hit counter code.

Check to see if the server’s or website’s caching systems are preventing the hit counter from working properly.

Instead of creating your own hit counter script from scratch, think about using a third-party service or pre-built script.

Thanks.

The count here seems to be working well:
https://bobbear.netfirms.com/PHPTestWebSite2/counter.php

It just needs to be read using fetch (or using XMLHttpRequest).

You can actually. First PHP processes the file and then Apache parses the SSI.

You can even let PHP generate SSI snippets for Apache to parse if you so wish.

1 Like

So how do you get Apache to do that? Usually an .shtml extension is used for SSI and a .php extension for PHP…

Tell apache to use INCLUDES on php files as well I suppose. I’ve never tried with Apache to be honest, but it works in NGiNX for sure.

@temp369 could try the following please?

<!--#include virtual='counter.php' -->
1 Like

Thank you all. rpkamp’s

<!--#include virtual='counter.php' -->

works. See try 0.
I am going back to embedded C programming and stay there!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.