【发布时间】:2015-01-29 05:28:16
【问题描述】:
我主要寻找性能、网站缓存、易于打字和安全性 - 优点和缺点
拆分文件并将它们作为包含项放入其中,这似乎是一种共享偏好
<?php
include('header.php');//and whatever includes inside
include('footer.php');//and whatever includes inside
?>
VS
将它们制成函数并在一个文件中调用它们,您可以在其中检查值并在两个函数之间共享它们,例如多样式选择
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/more-functions.php';
if(isset($_cookie['style']) || isset($_session['style'])){
if(isset($_cookie['style'])){$style = $_cookie['style']}else{$style = $_session['style']}
}
function siteheader($style){
if(!isset($style)){$style = 'default';}
print ('<http>');//insert rest of header
}
function sitefooter($style){
if(!isset($style)){$style = 'default';}
print ('</http>');//insert rest of footer
}
?>
【问题讨论】:
-
性能:可能存在细微差别,但没有什么实质性的差异,以至于您可以检测到它。另外:对其进行基准测试。缓存:没有任何影响。易于打字:自己决定。安全: ??? “安全”是什么?
-
附带说明,当变量为小写时,您无法访问 cookie/会话。它必须是
$_COOKIE/$_SESSION
标签: php performance caching