Including PHP script in HTML

Status
Not open for further replies.

chrisv

New Member
Messages
12
Reaction score
0
Points
0
Hi All,
I don't know what I'm doing wrong, I would like to include some PHP script in my HTML but it's not working. I found a thread where someone else was trying this and they got it to work :dunno:

Code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<p>This is an HTML line
<p>
<?php
echo "This is a PHP line";
?>
</body></html>

This is saved as a html, when I view it only "This is an HTML line" appears, no error messages...

Thanks.....
 

MaTe1968

New Member
Messages
33
Reaction score
0
Points
0
You need to save it as test.php and not test.html , thats why is not working!
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
Make a .htaccess and inside it put

Code:
AddType application/x-httpd-php .html

Then it should work fine.
 

chrisv

New Member
Messages
12
Reaction score
0
Points
0
Thanks all, I tried both solutions and the one suggested by zizou81 and MaTe1968 worked (ie. change from .html to .php)
Brandon, when I added the suggested line to the .htaccess file I got the following message:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Brandon, that was not the first mention that I saw for the .htaccess, is something else missing? The file already existed under public_html but was empty. If not I guess I just rename my htmls to phps.
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
That's weird, it works fine for me on the paid server, which is the server you are on correct?
 

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
.htaccess doesn't need to have any rules in it. It is fine empty.

Brandon's solution tricked the webserver into treating .html files like PHP files. It is better that you keep the .php extension on PHP files, so there isn't any confusion. If you're worried about people knowing you use PHP, check into Rewrite Rules for .htaccess.
 

chrisv

New Member
Messages
12
Reaction score
0
Points
0
Brandon, yes I am on the paid server, I did see this before and tried it and got the same error.

The_Magistrate, I would prefer to keep the files separate but right now the only way I can get this to work is by changing the extension to .php


Edit:
I got it figured out, Brandon you were very close it should be AddHandler not AddType.

Thanks to everyone for your help..... :biggrin:
 
Last edited:
Status
Not open for further replies.
Top