jagguy
asked on
cant read html
Hi, In my file called home.html this doesnt work unless I rename the file home.php
How do I make the html file pick up the php file with cpanel?
<div class="row-fluid">
<div class='span12'>
<?php include('includes/header.p hp'); ?>
</div><!--span12-->
</div> <!--row fluid-->
How do I make the html file pick up the php file with cpanel?
<div class="row-fluid">
<div class='span12'>
<?php include('includes/header.p
</div><!--span12-->
</div> <!--row fluid-->
ASKER
yes I know this but my question was to change the html file so it can read php commands.
Rename it as php.
Here is an excerpt from my .htaccess file. Very useful for working with HTML documents that just need a little bit of PHP :-)
AddType application/x-httpd-php5 .html .htm .php
File extensions exist for a reaon - they are used to give context to the file and specifically what applications can operate on them.
When you start changing the default behaviour you can create confusion.
It is expected that .html files are processed as such and .php files are passed to the php processor.
The question you need to ask is why do you want to do this.
If there is a genuine reason for needing to keep the file as a .html then first consider url rewriting. In your .htaccess enter a rule to rewrite your .html call as a .php call.
This way you expose the file externally as .html file but anyone looking at the code base will be able to see that index.php is a file that contains php script whereas a .html file will generally be overlooked as a file containing code.
To create a rewrite url in your .htacess just do as follows
When you start changing the default behaviour you can create confusion.
It is expected that .html files are processed as such and .php files are passed to the php processor.
The question you need to ask is why do you want to do this.
If there is a genuine reason for needing to keep the file as a .html then first consider url rewriting. In your .htaccess enter a rule to rewrite your .html call as a .php call.
This way you expose the file externally as .html file but anyone looking at the code base will be able to see that index.php is a file that contains php script whereas a .html file will generally be overlooked as a file containing code.
To create a rewrite url in your .htacess just do as follows
RewriteEngine on
RewriteBase /
RewriteRule index\.html$ index.php [L,NC,QSA]
You don't have to change your HTML + PHP documents at all. Please read this from the online man pages and then post back if you still have questions:
http://php.net/manual/en/security.hiding.php
http://php.net/manual/en/security.hiding.php
ASKER
OK why I need to do this is that for a website it is easier to have a template with header, menus and footer and just use this for all webpages.
Using includes with php is what you do.
Dreamweaver allows you to do this but I dont like .
Using includes with php is what you do.
Dreamweaver allows you to do this but I dont like .
OK why I need to do this...Erm, why do you need to put gasoline in a car for the engine to run? It's the way to make it work, that's all. You asked "How do I make the html file pick up the php file..." and this is the answer. It's about as easy as we can make it. And it's what the authors of PHP recommend.
Is there some reason why you don't want to do this? If so, please explain.
http://php.net/manual/en/security.hiding.php
In dreamweaver create the template main.dwt
then in that project for the home page of a website create a new page based on the main.dwt template and save as .. index.php
in dreamweaver you can set up defaults when creating projects so it will save it to the correct file extension save you having to manually save it.
upload to website and the server will execute the code in the file.
the answers above are all correct, if you use php code in your file you need to call it <filename>.php not <filename>.html. The web server will know what to do.
In the dreamweaver project if you rename the file, it will update all the references to that file if the file is used in the files of that project and then upload all the files that reference it.
then in that project for the home page of a website create a new page based on the main.dwt template and save as .. index.php
in dreamweaver you can set up defaults when creating projects so it will save it to the correct file extension save you having to manually save it.
upload to website and the server will execute the code in the file.
the answers above are all correct, if you use php code in your file you need to call it <filename>.php not <filename>.html. The web server will know what to do.
In the dreamweaver project if you rename the file, it will update all the references to that file if the file is used in the files of that project and then upload all the files that reference it.
ASKER
I should have said I dont have dreamweaver so the next best option for templates with php is?....
I assume you are happy with why your question about the HTML file is not being executed by the PHP engine? and now need to know how to template your PHP website?
what experience do you have in website design and PHP ? - this will help us determine what answer to provide and what sort of website do you want to create?
from simple flat multi page website to dynamic content from a database website to a framework website using wordpress or joomla or even synfony
what experience do you have in website design and PHP ? - this will help us determine what answer to provide and what sort of website do you want to create?
from simple flat multi page website to dynamic content from a database website to a framework website using wordpress or joomla or even synfony
this link provides an overview of what PHP framework is its goes beyond simple tempting of php code and turns a PHP website into a maintainable, extensible system, I wouldn't build a framework I would use one that widely used. (synfony, Yii, Smarty or CakePHP) this article uses TWIG to build an example
http://www.smashingmagazine.com/2011/10/17/getting-started-with-php-templating/
http://www.smashingmagazine.com/2011/10/17/getting-started-with-php-templating/
If you are interested in a very simple PHP template (or just understanding how a PHP framework works) you might find this article useful
https://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_13095-A-simple-PHP-master-Template-framework.html
https://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_13095-A-simple-PHP-master-Template-framework.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i answerd it
You have to name the file home.php so the code is parsed.
If you're referring to the home page of your site, then that should be called index.php and it will be displayed when navigating to http://yoursite.com/, if you do not have a index.html or index.htm.
HTH,
Dan