1.11M Members

My embedded php code won't execute

 
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!

 
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.

 
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.

 
0
 

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

 
0
 

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

AddHandler server-parsed .html

 
-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.

 
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.

 
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.

 
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....! :@

 
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 :)

 
0
 

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

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

 
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 :'(

 
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

 
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.

 
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".

 
0
 

just aside the reply thread button.

 
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.

 
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