我想在腳本的開頭添加一個打開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鏈接瞭解,我沒有設法做他們建議做的事...... –