Jump to content
xisto Community
Jimmy

Do You Want To Use Php Code In Your Html Pages? Within two minutes you will

Recommended Posts

Whilst searching around for help to setup cutenews blog I came across a way to use php in html pages - lo and behold it works! so I thought I'd share it with you all (Unfortunately I can't remember the site so I wrote this up a couple of minutes after I did it:) ).

This method requires a web server with apache installed. So, luckily for us all this covers the whole of Xisto... even Qupis :(

Just to make the point, this is in no way a difficult task and it doesn't require you to change your pages at all and you don't even have to rename them .php.
(This works for web files saved as both .htm and .html)


So Step 1 - Find the .htaccess file in the "public_html" root directory on your server.

Step 2 - Now, open the .htaccess file here with notepad - you can use the cpanel editor too - and add the following code to the file:
(If the file is not there create a new, empty file in notepad or another text editor and save it as ".htaccess" - Upload this and continue :lol: )
(If like me you have never done anything with this file it should be empty)

RemoveHandler .html .htm AddType application/x-httpd-php .php .htm .html

Step 3 - Save it and your done! Thats it :(

Now whenever you need to use php code, simply write it into the document and it will recognise the content as php and use it as you intended!

This is a sample code of what you have to do in your page... Nothing! Simply put the code in and Bob's your uncle >:lol:

<html> <head> <title>Php Test Page</title> </head> <body>    <div>   <?php echo "This Really Does Work!"; ?>   </div>  </body> </html>

And the best thing is... Your html pages still validate! so you don't have to decide between ease of use and getting you pages to validate; you can have it all :(

Hope this helped someone out.. It certainly helped me out

Share this post


Link to post
Share on other sites

Good job, Jimmy...

And here are a couple of links to Xisto Tutorials which are related to this Topic.
The following Tutorials share information about how to set up an Apache server onto your local machine which saves you from having to use the Trap or Qupis facilities to test your PHP code.

http://forums.xisto.com/index.php?sho32&hl=XAMPP
http://forums.xisto.com/index.php?sho17&hl=XAMPP

The XAMPP package includes Apache, MySQL, PHP4 and PHP5, Perl and several other softwares. (PHPadmin, an FTP server and a Mail Server, for instance)
In fact, you can duplicate the entire Xisto server set-up on your Localhost. Saves quite a bit of time and hassle since you don't need to upload all of your test cases.

Share this post


Link to post
Share on other sites
:( That is excellent I cant believe this…..it works……as I post just 15 min before I write this ….that I cant work php code on quips now…..after I see your solution I used it ….and it works. Ohhhhoooo.. :lol: This forum is really helpful as Im new here….Thanks I really mean it…. :lol:

Share this post


Link to post
Share on other sites

im surprised this works but i believe all of you! if im right its the same code that goes into .htaccess as that which makes the dynamic signatures with the ip's and browser info etc... but i would have thought that as it is treating HTM pages as php ones that it would throw an error when you use raw HTML as a normal php file would as its not the right syntax. Anyone know why it doesnt throw an error? or maybe it does but no-one mentioned it and i havent tried it myself

Share this post


Link to post
Share on other sites

The php parsing must be invoked by the php start and end tags, otherwise, the php parser treats all files as html, so re-directing html files through the php parser is no big deal. Although it does add an additional step to the throughput, so the delivery of the page is *somewhat* slower. Unless you are parsing 100k files with mega database calls, you'll not notice the change, but it is a little more demanding of the Server resources.

Share this post


Link to post
Share on other sites

It's not really good to do that. It's better to have a PHP file with a header and a footer of HTML included so that you can make universal changes to your site, and not have to deal with modifying multiple files just to get the template working unless you deal with JS and CSS files.

Share this post


Link to post
Share on other sites

That's the thing, Tetra, you can do exactly what you are saying, only with an html file extension if you add the posted code into your .htaccess file. The file contents would be the same whether you use the php or html file extension. It just conceals the fact that there is a php script running because when someone looks at your URL, it appears to be an html file.

Share this post


Link to post
Share on other sites

It's not really good to do that. It's better to have a PHP file with a header and a footer of HTML included so that you can make universal changes to your site, and not have to deal with modifying multiple files just to get the template working unless you deal with JS and CSS files.

Hmmm... the thing about this was if you have a html page, and you need to insert a small bit of php, instead of forcing you to change everything to xhtml standard or re-write your site as php and put it in, you can simply do this and it will work fine. As above, you're really describing the same thing, just in a different way (where it can be done with .htm and .html files instead of php files with a different extension) !As Jim said, It would technically make everything slightly slower, but unless your pages are > 100K and your querying huge databases, you really won't notice the difference :lol:

Dotasif: Glad I could be of help ! Its really nice to know someone benefited already from this :(

Shadowx: Nope, it gives no error (that I'm aware of!!) And simply does what it says on the tin :lol:.
Edited by Jimmy (see edit history)

Share this post


Link to post
Share on other sites

Or you could've just renamed the file.html to file.php and added the php script :lol: As long as the output HTML is good it won't affect anything whatsoever... The only useful thing I can thing of that comes out of this is hiding the fact that you're using PHP. But I don't see the point because if you know PHP that means you're more skilled than someone who just knows HTML...Now if you're doing that to get rid of file.php?this=that&that=this, I can see what you're getting at with SEO. But why not just use mod_rewrite instead?

Share this post


Link to post
Share on other sites

Ah well, corrected i stand..or sit.. I suppose one advantage is if a potential hacker...if you can call them that... sees a php page they know that there is a chance for user input and database and more potential fr an exploit perhaps. I know that static HTML pages are only really vulnerable if someone gains your login details or access to your server whereas anything taking input, like php pages is vulnerable...though seeing a login box or something would obviously show sme server-sides are in use.And it would help in SEO for the reason above but would it also help in that the search engine thinks its looking at HTML pages and better indexes the content? Im probably wrong because ive not really dont any SEO in any detail and i havent much idea how a search engine works other than the basic explanations.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.