Include php from html

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi - I have been asked to add a hit counter to a standard HTML page.
I have found a php script to implement the counter but need to show it
on the html page.
I cannot include a PHP in the html file can I? the web server will not
pre-parse a html file correct?

I would like to put the PHP hit counter on the web site that only
contains html files. Anyone have a good idea how I can do this without
chaning all the files to .php?

Luke Bellamy
Newcastle, Australia

Re: Include php from html

It is most definitely possible to include a PHP counter in an HTML file
because I have been doing it for years. In my HTML file I include a link as

<p><img src=" "
alt="counter" border="0"></p>

The PHP script 'counter.php' uses the 'page=' argument to identify which
document to count, then outputs the result as an image.

Easy peasy lemon squeezy.

Tony Marston

Quoted text here. Click to load it

Re: Include php from html

*** Luke Bellamy wrote/escribió (28 Apr 2005 20:16:29 -0700):
Quoted text here. Click to load it

You can instruct the webserver to pass *.html files through PHP
interpreter. If you are using Apache you may be able to use an .htaccess
file (unless prohibited by sysadmin):

# For Apache 2:
<Files *.html>
    SetOutputFilter PHP
    SetInputFilter PHP

-- Álvaro G. Vicario - Burgos, Spain
-- - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group

Re: Include php from html

You could also display the counter in a frame or <iframe> on the page,
I've done it before, sorry I can't give you an example right now, I
havn't used frames in ages

Re: Include php from html

On Thu, 28 Apr 2005 20:16:29 -0700, Luke Bellamy wrote:

Quoted text here. Click to load it

Of course you can. That is what <?php....?> is for. Rough template looks
like this:

<?php Requires, class declarations and alike?> </head>
<?php action ?>

It is one of the biggest advantages of PHP that is freely mixable with
HTML. Otherwise, you could use perl instead.

Egoist: A person of low taste, more interested in themselves than in me.

Site Timeline