Solved

PHP not rendering on HTML page with IIS

Posted on 2009-04-09
20
1,262 Views
Last Modified: 2013-12-13
Hi,

I have IIS 6 installed with PHP added to IIS so that it can process any PHP code. My PHP code works fine on most pages, but I am having an issue with one particular page.

When I added the tags and try to echo some text, but nothing gets displayed. The weird thing is that it recognizes the PHP tags because it does not display them, but it does not echo any text either.

FYI, I have added the php5isapi.dll file into the application extensions for the website. Also, PHP is able to execute on other pages.

Thanks!

0
Comment
Question by:aseem1234
  • 9
  • 6
  • 3
  • +1
20 Comments
 
LVL 10

Expert Comment

by:webwyzsystems
ID: 24109064
Sounds like it's just a syntax error. Remember that many installs of php suppress errors by default. Try sticking this at the top of your php file:

ini_set('display_errors', 1);

And then run the script. Hopefully it will spit back the error.
0
 

Author Comment

by:aseem1234
ID: 24109136
Hi webwyzsystems,

I checked to make sure it's not a syntax problem. This is the code:

<?php echo "testing"; ?>

I tested it out elsewhere and it works fine.

Any other ideas?

Thanks
0
 
LVL 3

Expert Comment

by:Duboux
ID: 24109164

Maybe you got allow-short-tags = off in php.ini.
And on that particular page you use <?  instead of <?php
0
 

Author Comment

by:aseem1234
ID: 24109201
Duboux,

I'm using <?php on that page, not the short hand notation.
0
 

Author Comment

by:aseem1234
ID: 24109224
I'm sorry, this page I am talking about is a .HTML page, not .PHP. I thought it was .PHP, but it's actually .HTML. The PHP code works fine on .PHP pages, but how would I get it to display on .HTML pages?
0
 
LVL 3

Expert Comment

by:Duboux
ID: 24109240
aaah, hehe

You can't

Unless you use a nasty html-include of a file or an iframe, or have javascript fetch the php stuff..

But the fastest fix, is to rename the file-extension to .php lol !
0
 

Author Comment

by:aseem1234
ID: 24109257
Isn't there anyway to do it using MIME types in IIS? I swear there is some way to display PHP in a HTML file...
0
 
LVL 10

Expert Comment

by:webwyzsystems
ID: 24109305
hmmm...
I am assuming the file is xxx.php and you are not trying to use php in a file with a .html extension..
Is PHP allowed in the directory where you are saving the file?

EXAMPLE:
You can turn PHP on and off with this in the PHP.ini
<Directory /home/*/public_html>
php_admin_flag engine off
</Directory>

The same way you should be able to only activate the engine in
directories where you really want it to work like:

<Directory /home/*/public_html>
AddType application/x-httpd-php .phtml
</Directory>
0
 
LVL 10

Expert Comment

by:webwyzsystems
ID: 24109325
lol...I posted then saw all the rest of it...
0
 

Author Comment

by:aseem1234
ID: 24109379
webwyzsystems,

Can I add that to the php.ini file to tell it to parse PHP code in an HTML file? If so, where in the php.ini do I need to add it?

Thanks
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24122656
aseem1234,

This isn't done in the INI.  It would be in IIS or whatever your web server is.  Is this a hosted site or your own server?  Do you know what you are using to handle PHP (e.g. php_isapi, fastCGI, etc)?

You need to map the php processor to html files.  The specifics will depend on what you are using to process php.  I can try to provide specifics on how to do this if you can provide that detail.  If your site is hosted you need to ask your provider to do this but they may not be willing to do it.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Comment

by:aseem1234
ID: 24130898
Hi b0lsc0tt,

Thanks for your help. Yes we are hosting the site on our own servers. Also, we are using php_isapi for handing PHP.

How would I go about mapping the php processor to HTML in IIS? We are currently using IIS 6.0.

Thanks for your help!

Aseem
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24131424
The area to make the change is in the Properties for the site.  Access IIS Manager and right click on your site's folder in the Web Sites area.  Choose Properties from the options that appear to get the screen you need.  Find the Home Directory tab and select it.  You should see something like Image1 below.
On the Home Directory tab you click the Configuration button to bring up the Mapping screen you see in Image2.  You will need to add an entry for html (or htm) to have that file extension handled as a PHP file.  You can look at the current entry for PHP to see the settings to use when you add the mapping.
These steps are getting out of my expertise a bit but am pretty sure they are what you need and all you need for this.  Let me know if you have a question or how they work.
bol

IIS-SiteProperties-HomeDirectory.png
IIS-SiteProperties-HomeDirectory.png
0
 

Author Comment

by:aseem1234
ID: 24131924
Hi b0lsc0tt,

Thanks for the great tip! I think we are very close now. I went ahead and added an entry for a .HTML extension (what we are using) and I pointed it to the phpisapi.dll file that the .PHP file extension was using.

I stopped and started IIS, but it's still not rendering the PHP. Like I said above, it recognizes the PHP tags because it removes those completely, but it won't show any text I am trying display using the ECHO command.

Any other ideas?

Thanks!
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24133902
>> it recognizes the PHP tags because it removes those completely,  <<
Actually that isn't really true.  I know you mentioned that before and maybe it could be true based on your point of view but it doesn't really recognize them as PHP tags, just as tags it doesn't know what to do with.  That is why you don't see what you have inside, even the code.  It is actually a nice protection of recent IIS versions.  Earlier ones would've shown the code.
What if you add an entry just like that but use the letters php5 (e.g. .php5)?  Rename on of your .html files to .php5 instead (first part of name can stay the same).  What is the result?
I was able to test on a machine with a pretty similar set up.  I did .htm instead but it worked.  Most likely there is something in the mapping you are missing or have wrong.  Take a screenshoot of both screens if you can't see the problem and post them here.
Make sure you have restarted IIS after making the change.  That type of change doesn't take effect until the server is restarted.
Let me know how this works or if you have a question.
bol
0
 

Author Comment

by:aseem1234
ID: 24138682
OK, so I took a screenshot of my settings and attached them here. I cannot change the extension from .HTML because this site is not allowed by our administrator. If I want PHP, I have to get it to execute in the HTML files.

Also, I don't know if it makes any difference, but the DefaultApplicationPool is running under the Network Service identity. I have attached a screenshot of the directory security and the identity.

Thanks for your help! I am upping the points to 450!
IIS-Application-Pool-Settings.gif
IIS-Directory-Security.gif
IIS-Home-Directory.gif
IIS-Mappings.gif
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24139864
So do .php files work on your server right now?  It sounds like the admin won't want to leave the server configured to support them (doesn't make a lot of sense to me unless every .html file will have php code) but hopefully it is still set up and configured to support .php files.  Please try to make sure your page will show what the php code will echo when the page has the .php extension.  I am concerned that php just isn't really set up to be processed by your server.
I do see the "verb" part of the entry for .html in the mapping isn't correct.  I really doubt it will make a difference but it would be best to have the following there instead of ALL verbs:
GET,HEAD,POST
Please click edit (in the IIS-Mappings image when .html is highlighted) and provide a screenshot of the settings for the .html mapping.  I have provided a screenshot of the default set up for .php mapping below.  Maybe you have not checked the box for the Script Engine (I think that is what the setting is called).  Otherwise please provide a screenshot of yours.
bol

IIS-SiteProperties-HomeDirectory.png
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 450 total points
ID: 24140009
By the way ... I am not real sure where that first screenshot came from.  I don't really think the application pool would stop this from working, especially just for .html.
I am wondering though if your admin really understands what you are doing and if this is the best option.  I hinted at it before but unless every .html file will have php script it really is a waste of server resources (and might even be risky) to have every file processed by the php "engine."  Of course I don't know what else the server does or what may prompt that limitation but it seems odd to allow this type of modification and not just allow the default type.  Usually the "policy" would be to either allow no server scripting (although it looks like .NET may be an option for you) or allow server script as it is usually configured.
Can you use .NET?  If so what are you trying to do in PHP?  I would really consider working with what your server will support instead of trying to get a "customized" solution like this working.  Of course that is just my opinion from experience and the info I have here. :)
bol
0
 

Author Comment

by:aseem1234
ID: 24306739
Sorry for the late response, the PHP code inside HTML didn't end up working. I ended up having to do something different in order to solve my issue. I'll give you half the points for helping.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24310795
I am going to post this as an objection.  I appreciate your last comment to let me know the status of this and the results.  I don't really understand why you are accepting your comment as an answer though and reducing the points.  I can understand there are reasons that PHP just won't work in the html file (because of the server changes needed) but it seems my expert comments gave you the info to get to that point too.  I understand you made a decision and it may even be different than what you originally hoped but don't see why your comment is an answer to this.  Please explain.
I am glad I have helped and thanks again for letting me know the status.
bol
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now