PHP code in HTM not working

I have just setup account and have some existing HTM files that include a menu (PHP). I am not seeing the php file show up in the htm. I have had this same code working on another web hosting site. I can see the php menu show up in a web browser so I know it is working. Is there something I need to enable on my site for php use? Thank you.

In order to run the file through the PHP interpreter, you must be using the PHP extension

6 Likes

This means that you must have the .php file extension instead of the .html or .htm extension. This is because PHP only detects and executes files that have the .php extension.

5 Likes

Maybe I need a little more explanation. This is the code in my htm file that I use to bring up the menu.

<div id="menu">Short Cut To:<br />
         <?php include "menu.php"; ?></div>


This is what I get; a blank spot where the menu should be.
Thanks

Could you share the URL to the page where this code runs? It would help a lot if we could take a look at it ourselves.

My first guess is that the menu.php file doesn’t exist. That would cause the include directive to not respond with any content and render as blank.

5 Likes

http://bd-travel.infinityfreeapp.com

none of them are PHP files but HTML

So it’s normal that this code doesn’t work

PHP files have extension “.php”

besides that, you don’t have an index file anywhere

and I also see some files which were uploaded but that do not play a role here

5 Likes

You may be able to get the server to process you HTML code as PHP code by adding a .htaccess line like the one from this article:

Note that I haven’t tested this. And I would strongly recommend to not go this route and instead make sure that files that contain PHP code that should be executed have the PHP extension.

And if you insist on having URLs that end with .htm, you can use .htaccess rules to rewrite the .htm extension to .php.

4 Likes

I’m sorry I pointed you to the wrong directory. When you said the url, I thought you meant my main page. The directory specifically is at http://bd-travel.infinityfreeapp.com/TripMar2015/ There you will find the menu.php file and htm files that reference it. As you might tell I don’t have a lot of experience in this area but I did have the same code working on my last web hosting company. Thanks for your help!

The location may be different, but the exact same answers apply: the PHP code in the .htm files doesn’t get executed as PHP code. Only PHP code in files with the .php extension will get executed.

This is how most web servers work (and should work IMO). But as I wrote before, it may be possible to customize this behavior, and your previous host may have just run all files through the PHP processor.

But again: same issue, so same answers, and same proposed solutions.

5 Likes

Thanks, I found my answer here: How to run PHP codes in .html files using .htaccess

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.