Why won't my PHP work in HTML?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

Why won't my PHP work in HTML?

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

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

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

Post 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.
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

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

Post 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?! :?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Well... Didn't I mention that?!
Err yeah sorry I read it out of context
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

That's ok :P
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

Post 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?
vincenzobar
Forum Commoner
Posts: 95
Joined: Wed Nov 02, 2005 9:57 am

Post 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

Post Reply