1,105,581 Community Members

My embedded php code won't execute

Member Avatar
techhelpforme
Light Poster
29 posts since Aug 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This works:

-----------PrintInfo.php
<?php
phpinfo();
?>
--------------------------

But this doesn't:

-------------PrintInfo.html
<html>
<head>
<title> Hello World </title>
</head>
<body>
<?php

echo 'This is my first PHP web page.';

?>
</body>
</html>
-------------------------

I'm using Apache 2.0 on WinXP Home with php 5.

Thanks!

Member Avatar
Roberdin
Supreme Evil Overlord
282 posts since Feb 2003
Reputation Points: 9 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
Team Colleague
 
0
 

It has to end in .php to be parsed by the PHP engine, change your file name back to PrintInfo.php.

The HTML code (within the PrintInfo.php code) will not be analysed by the PHP parser, bnut instead be sent straight to output. The PHP parser only reads between the <?php and ?> tags.

Member Avatar
techhelpforme
Light Poster
29 posts since Aug 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

It has to end in .php to be parsed by the PHP engine, change your file name back to PrintInfo.php.

The HTML code (within the PrintInfo.php code) will not be analysed by the PHP parser, bnut instead be sent straight to output. The PHP parser only reads between the <?php and ?> tags.

Thanks Roberdin. Sorry I should have specified that I'm trying to make web pages with embedded php work, so I was wanting .html files to work. I found out I needed to add this line to my httpd.conf file in the Apache directory:
AddType application/x-httpd-php .html
to get apache to associate .html files with the php engine.

Member Avatar
PoA
Posting Whiz in Training
234 posts since Jul 2004
Reputation Points: 12 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Another way round to use .html is use mod_rewrite to convert .php to .html (any file format you can convert)

Member Avatar
felgall
Junior Poster in Training
56 posts since Aug 2004
Reputation Points: 1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

The command to add to .htaccess to get html files treated as php is:

AddHandler server-parsed .html

Member Avatar
dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
-1
 

The command to add to .htaccess to get html files treated as php is:

AddHandler server-parsed .html

Ok, I know this is an old thread but just ran across it.

How can you do the same as above in IIS. It's in the planning stages to convert to Apache but that may or may not happen.
In any case, do to some restrictions(long story) I HAVE to use .HTM as the first called document. I can use that to run into .PHP docs but it would be nice to be able to start in PHP for some dynamic forms development.

Member Avatar
vaultdweller123
Posting Pro
577 posts since Sep 2009
Reputation Points: 32 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 2 [?]
 
0
 

you can't run php code inside a .html files.... your files should be saved as .php so it will be parsed at the server.

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

you can't run php code inside a .html files.... your files should be saved as .php so it will be parsed at the server.

Actually you can - but it means using htaccess files (as mentioned previously) or using a templating engine (e.g. Rain TPL) which stores cached php files of htmls. For everyday use, I really can't see what advantage there is to be gained from using the *.htm(l) extension if you're using server-side code.

Member Avatar
vaultdweller123
Posting Pro
577 posts since Sep 2009
Reputation Points: 32 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 2 [?]
 
0
 

Actually you can - but it means using htaccess files (as mentioned previously) or using a templating engine (e.g. Rain TPL) which stores cached php files of htmls. For everyday use, I really can't see what advantage there is to be gained from using the *.htm(l) extension if you're using server-side code.

hey ardav! you always contradict at my every post! grrr....! :@

Member Avatar
ShawnCplus
Code Monkey
1,564 posts since Apr 2005
Reputation Points: 456 [?]
Q&As Helped to Solve: 269 [?]
Skill Endorsements: 39 [?]
Team Colleague
 
0
 

hey ardav! you always contradict at my every post! grrr....! :@

Well, ardav is correct so he is completely within his right to make a post :)

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

hey ardav! you always contradict at my every post! grrr....! :@

Sorry VD, wasn't intentional - no vendetta, honest! Cheers Shawn.

Member Avatar
vaultdweller123
Posting Pro
577 posts since Sep 2009
Reputation Points: 32 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 2 [?]
 
0
 

Well, ardav is correct so he is completely within his right to make a post :)

you too! hey im just a newbie... and im just sharing what i know a little about php :'(

Member Avatar
dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Actually, if everybody would have read my post they would have seen
1. Yes you can in Apache with some .htaccess modifications.
(noted in previous posts and was a fix for the original question.)
2. I'm not running Apache, I'm running IIS so those modifications will not work in my case.
3. I have some restrictions that REQUIRE me to use a .HTM extension as a "landing page" and can pass data to PHP from a form but I HAVE to use the .HTM extension first.

In any case, we have found a work-around for this problem so I no longer need to modify the IIS server data. Thanks anyway

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

In any case, we have found a work-around for this problem so I no longer need to modify the IIS server data. Thanks anyway

Mark it solved then.

Member Avatar
dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Well, technicaly, it wasn't "solved" being that the question wasn't answered. We just decided to go another route, abandoning the idea.
Oh, and being a new person on this forum, I have no idea how to mark this "solved".

Member Avatar
vaultdweller123
Posting Pro
577 posts since Sep 2009
Reputation Points: 32 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 2 [?]
 
0
 

just aside the reply thread button.

Member Avatar
dreaogse
Newbie Poster
5 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
1
 

hmmm, it might be because I wasn't the originator of the post but that option is not available to me for this thread.
I even had a couple of other people look. Just in case I was missing it for some reason.

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Fair one. A lesson to a few of us (me especially) to read the posts properly.

Question Answered as of 1 Year Ago by diafol, dreaogse, vaultdweller123 and 4 others
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article