Using PHP code on an htm page

21 posts by 2 authors in: Forums > CMS Builder
Last Post: April 23, 2010   (RSS)

By jsnook - April 17, 2010

www.cottagenet.com

I am a new use. I have installed and have running the latest version of cms Builder. I have created a table and can copy and paste the code into a php web page and it runs fine, but when I try the same code on an htm or html page it doesn't work. The code "bleeds" through to the main page (that customers see) and clearly is not understood by the .htm system.

I have created a .htaccess.txt file (or should that be .htaccess without the .txt extension? - I have tried both) and uploaded it to the root directory (as it says in the instructions) but this makes no difference. Here is the .htaccess.txt file:

"Addhandler application/x-httpd-php .html .htm .php"

So the code functions ok in a php environment but not on an htm page which is what my site is written in.

I'm rather stuck. Suggestions please

Re: [jsnook] Using PHP code on an htm page

By Jason - April 19, 2010

Hi,

The easiest thing would be to just change your files from .htm to .php. The nice thing is that you wouldn't have to change any of the html coding in your pages. The .php extension just tells the server to execute any php code found on the page. Any HTML that is not surrounded by the <?php ?> brackets will display normally.

Maybe give it a try with one file and see how it works. If you run into any problems, just let me know and attach the file you're working with.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Using PHP code on an htm page

By jsnook - April 19, 2010

Thanks for then info but the problem is that I want to use the system on htm pages already on the server and indexed by the search engines. I can't change the name as i will loose my ranking. I have found out that I am on a Zeus server not Apache. Is there a way of pasting in the php code but keeping the file extension htm?

Re: [jsnook] Using PHP code on an htm page

By Jason - April 19, 2010

Okay, you can try this line in you .htaccess file

AddType application/x-httpd-php .html

Note, that .htaccess is like a system file. It shouldn't have a .txt extension. Give it a try and let me know how it works out.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Using PHP code on an htm page

By jsnook - April 20, 2010

thanks - tried this but it made no difference. I also changed html for htm but the same error occured. It still wont allow php in an htm page

Re: [jsnook] Using PHP code on an htm page

By Jason - April 20, 2010

Hi,

Try replacing what we did before with this in your .htaccess file:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html


If that doesn't work, maybe attach your .htaccess file and I'll take a look.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [jsnook] Using PHP code on an htm page

By Jason - April 21, 2010 - edited: April 21, 2010

Hi,

Another thing you could try would be to put all of your code into a .php file. Then, in your .html file, use a javascript redirect like this:

<script type="text/javascript">
window.location = "mypage.php";
</script>


Hope that helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Using PHP code on an htm page

By jsnook - April 21, 2010

Could not actually get this code to work but I think this is the way to go. I Managed to get the php file to show on the htm page using an iframe but the problem with this method is that the text produced is not spiderable (eg by Google) as it is simply a "picture" of the original text. Can you test your original code again or is there a way of getting the ifram to show real text? Perhaps there is another way to display the php file on the htm page?

Thanks for your efforts

Re: [jsnook] Using PHP code on an htm page

By Jason - April 21, 2010

Hi,

Sorry, I made a small error. I've fixed it. Try the new code and let me know if that works. It would be the easiest way to go.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/