我想在脚本的开头添加一个打开IF条件的PHP文件。然后我写我的脚本,并完成我包括另一个PHP文件关闭条件。包含打开条件的PHP文件,但在另一个包含的PHP文件中关闭
这使我到“解析错误:语法错误,意外的文件结尾...”错误。
这将是更好地与这个简单的例子就明白了:
的header.php
if(aConditionalTest()) {
footer.php
} // endIf
mypage.php
include_once 'header.php';
echo 'my awesome content';
include_once 'footer.php';
FYI:我想例如做到这一点:
- 检查无处不在,用户正在显示的内容
- 实现网页缓存系统之前,授权(见http://www.phpfastcache.com/在“示例”部分,“缓存整个网页”)
谢谢!
编辑:解释更准确地说我为什么要使用phpfastcache做到这一点:
http://www.phpfastcache.com/说:
Caching Whole Webpage PHP Cache whole web page : You can use phpFastCache to cache the whole webpage easy too. This is simple example, but in real code, you should split it to 2 files: cache_start.php and cache_end.php. The cache_start.php will store the beginning code until ob_start(); and the cache_end.php will start from GET HTML WEBPAGE. Then, your index.php will include cache_start.php on beginning and cache_end.php at the end of file.
这正是我努力去做! 根据他们的片下面的代码,这带来了在该处进行条件中的“cache_start.php”打开和随后关闭在“cache_end.php”
cache_start.php情况
use phpFastCache\CacheManager;
$cache = CacheManager::Memcached();
$keyword_webpage = md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING']);
// try to get from Cache first.
$resultsItem = $cache->getItem($keyword_webpage)
if(!$resultsItem->isHit()) {
ob_start();
cache_end.php
// GET HTML WEBPAGE
$html = ob_get_contents();
$resultsItem->set($html)->expireAfter(1800);
$cache->save($resultsItem);
}
echo $resultsItem->get();
mypage.php
include_once 'cache_start.php';
// my awesome content to cache goes here...
include_once 'cache_end.php';
myotherpage.php
include_once 'cache_start.php';
// my other great content to cache goes here...
include_once 'cache_end.php';
所以我为什么要放2个独立的文件中phpfastcache代码的原因是,我有许多不同的PHP页面缓存,所以我想avoir在每个页面上重复所有这些代码...
希望这个编辑能够帮助你更好地理解为什么我会那样做,即使我理解,正如我担心的那样,这是不可能的。
哎哟...那不行。 – CD001
问题是什么? –
问题是“我怎么能做到这一点?“看到phpfastcache链接了解,我没有设法做他们建议做的事...... –