Page 1 of 1

Why won't my PHP work in HTML?

Posted: Wed May 03, 2006 2:46 pm
by bwv2
I have just changed my main page from index.php to index.html. In the process I had a bunch of stuff changed in the code to make it ready for the public domain, but now my embedded PHP code doesn't work.

I was under the impression that PHP could be integrated by simply using the <? ?> insertion tags in html documents. Here's an example of my page. Note that the <? session_start()?> doesn't work, and neither does the $_SESSION call in the signin box.

Code: Select all

<? session_start();?>
<html>
<head>
<title>The Page</title>
<meta http-equiv="Content-Type" content="text/html;">
.
.
.
<table ALIGN="CENTER" BORDER=0 id="text">
<form name="theForm" action="./sheets/getin.php" method="POST">
<TR><TD><h3>Sign In</h3></TD></TR>
<tr><td>Username:</td><td><input type="text" name="username" value="
     <? if(!empty($_SESSION['username'])){
          echo $_SESSION['username'];
         }else echo ""; 
     ?>"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
<tr><td><input type="submit" value="login" name="submit"></td></tr>
</form>
</table>
Any ideas?

Posted: Wed May 03, 2006 2:52 pm
by feyd
php probably doesn't know you want to process .html files as a php file. Depending on your web server, this could be a change in the control panel, a change of the httpd.conf or some other area.

Re: Why won't my PHP work in HTML?

Posted: Wed May 03, 2006 2:53 pm
by Oren
bwv2 wrote:I was under the impression that PHP could be integrated by simply using the <? ?> insertion tags in html documents.
That's wrong.
You can set your server to treat HTML files as PHP though.

Re: Why won't my PHP work in HTML?

Posted: Wed May 03, 2006 6:20 pm
by Ollie Saunders
Oren wrote:
bwv2 wrote:I was under the impression that PHP could be integrated by simply using the <? ?> insertion tags in html documents.
That's wrong.
You can set your server to treat HTML files as PHP though.
I wouldn't say its wrong. You just have to have your server configured correctly.

Posted: Thu May 04, 2006 2:48 am
by someberry
You need to inform Apache (I assume you are using Apache) that you want .html files parsed as PHP. Add this to your .htaccess file:

Code: Select all

AddType application/x-httpd-php .html
If you want to add more extentions to be parsed as PHP, then do this:

Code: Select all

AddType application/x-httpd-php .html .htm .css .png

Re: Why won't my PHP work in HTML?

Posted: Thu May 04, 2006 2:58 am
by Oren
ole wrote:
Oren wrote:
bwv2 wrote:I was under the impression that PHP could be integrated by simply using the <? ?> insertion tags in html documents.
That's wrong.
You can set your server to treat HTML files as PHP though.
I wouldn't say its wrong. You just have to have your server configured correctly.
Well... Didn't I mention that?! :?

Posted: Thu May 04, 2006 3:38 am
by Ollie Saunders
Well... Didn't I mention that?!
Err yeah sorry I read it out of context

Posted: Thu May 04, 2006 3:43 am
by Oren
That's ok :P

Posted: Thu May 04, 2006 9:20 am
by bwv2
Okay, so how would I go about changing my server settings to allow php in html? Is it something in the php.ini file?

Posted: Thu May 04, 2006 9:34 am
by vincenzobar
ass mentioned above you have to allow HTM or HTML to read as php in your .htaccess file or in httpd.conf
Also make sure your server allows users to use htaccess in your httpd.conf

Code: Select all

Options +FollowSymLinks
RewriteEngine on
AddType application/x-httpd-php .html .htm