> Why cannot I embed php in html files?

        I'm relatively new to PHP, but I am fairly sure that it is
possible to have PHP embedded in .html files, as my web hosting service
accomplishes exactly that. I believe it's just some kind of setting in
Apache or somewhere else that you or your web hosting service can
configure.
        On my web hosting service, the file can have a .html extension,
but there must be <?php ?> tags at the very beginning of the file, on
the very first line before absolutely any HTML code, including doctype
headings. If you want your PHP to work it's magic somewhere else in the
page, and not at the very beginning, it's no problem, just put some
harmless bit of code at the beginning, and then place whatever it is
that you really want to do within separate <?php ?> tags where you want
it.
        Personally, because I work with software that generates
templates for all my web pages, I put the following code at the start of
every page:
<?php
session_start();
?>
        I chose session_start as a command because I often need
sessions, and if there is a session, it needs to happen before the HTML
<head> tag anyway. If one of the pages based on my template doesn't have
a session, or even if it doesn't use any PHP at all, then the HTML
parser seems to just ignore the <?php ?> tags and whatever is in it and
output the .html file no problem.

        Bottom line - speak to your web hosting service about
configuring .html files to be parsed by the PHP engine. If you're
running your own server, then you'll need to consult someone more
advanced than I. Also, I can't ensure there aren't any errors or
drawbacks to my advice, I'm just relaying how my web hosting service
seems to handle the issue.

        Hope that helps.

-- 
Yoroshiku!
Dave G
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to