开发者

HTML VS PHP comparision

Is it better to have HTML files for including as heade开发者_StackOverflowr and footer in a PHP application instead of PHP files?


I usually do something like the following to keep things neat and consistent:

<?php require_once('includes/header.inc.php'); ?>

<!-- Html here -->

<?php require_once('includes/footer.inc.php'); ?>

If your webapp is written in php I see no reason to deviate away from the php extension as you may want to add some dynamic content into the include at a later date.


including as an header and footer in php application is good

like

index.php


include_once('header.php');
// your code regarding this page
include_once('footer.php');


It depends - if you have static header and footer html is enough. If you need there any kind of dynamic, then php comes to fight.


when you are building just some very simple php web page i suggest using require_once to include basic layout of the page. It doesnt matter if you are including html or other php code and you should know whether you would benefit from php or not.

Also including html is faster then including php code which is just calling many echos or prints.


Provided you use secure PHP code, it does not make a (significant) difference. I would suggest separating the main application concerns from your header and footer files, to avoid placing costly operations which may be unecessarily repeated in these files. Some guidelines to address possible security issues can be found here: http://phpsec.org/projects/guide/.


If you are using kinds of include for inclusion, the file type doesn't matter, the PHP code in it will execute, if there is one. Note that this is also a subtle security concern.

Because of this, I don't think the file type is relevant in this. The real question is what have you got in the footer and the header, e.g. PHP processing, database calls, ...?


I personally think that is better to require_once your php header and php footer. Maybe it is a bit slower thant hmtml (but not very relevant) but this unnecessary "optimization" doesn't worth the certainly needed php functions used in your header like session_start() or mysql_close() in your footer.

My personal point of view though :)


There is nothing better in including HTML
moreover - a real life will tell you that you can't use plain HTML anyway.

I've answered similar question recently, with strong reasoning: Using PHP include to separate site content


This is what I do

index.php

<?php
include_once('header.php');
//Your code goes here
include_once('footer.php');
?>

and yes it is a better practice to use php files as header and footer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜