Hi, Khách!
![]() | ![]() ![]() ![]() ![]() |
Mod thì cũng đơn giản thôi, nguyên lí thì vô cùng đơn giản nữa

Bạn tạo 1 folder tên là Cache để vào trong thư mục forum
code đã:
# Cache nội dung bài viết
$file = $_SERVER['HTTP_HOST' . $_SERVER['REQUEST_URI';
$cachefile = 'Cache/' . md5($file) . '.html';
if(file_exists($cachefile))
{
include($cachefile);
} else {
# code show nội dung
$cached = fopen($cachefile, 'w');
fwrite($cached, $content);
fclose($cached);
}
Copy code
$file = $_SERVER['HTTP_HOST' . $_SERVER['REQUEST_URI';
$cachefile = 'Cache/' . md5($file) . '.html';
if(file_exists($cachefile))
{
include($cachefile);
} else {
# code show nội dung
$cached = fopen($cachefile, 'w');
fwrite($cached, $content);
fclose($cached);
}
Copy code
bạn mở file show bài viết ra , tìm cái đoạn mà gọi là xuất ra nội dung bài viết ấy rồi chèn code trên vào
giả sử đoạn show nội dung của mình là
$content = htmlspecialchars($t['m'['text',ENT_QUOTES,"UTF-8");
$content = bbcode::tags($content);
$content = nl2br($content);
$content = ModPrince::ModBbcode($content,$t['t'['text');
echo $content;
Copy code
$content = bbcode::tags($content);
$content = nl2br($content);
$content = ModPrince::ModBbcode($content,$t['t'['text');
echo $content;
Copy code
thì sẽ chèn như thế này
# Cache nội dung bài viết
$file = $_SERVER['HTTP_HOST' . $_SERVER['REQUEST_URI';
$cachefile = 'Cache/' . md5($file) . '.html';
if(file_exists($cachefile))
{
include($cachefile);
} else {
$content = htmlspecialchars($t['m'['text',ENT_QUOTES,"UTF-8");
$content = bbcode::tags($content);
$content = nl2br($content);
$content = ModPrince::ModBbcode($content,$t['t'['text');
echo $content;
$cached = fopen($cachefile, 'w');
fwrite($cached, $content);
fclose($cached);
}
Copy code
$file = $_SERVER['HTTP_HOST' . $_SERVER['REQUEST_URI';
$cachefile = 'Cache/' . md5($file) . '.html';
if(file_exists($cachefile))
{
include($cachefile);
} else {
$content = htmlspecialchars($t['m'['text',ENT_QUOTES,"UTF-8");
$content = bbcode::tags($content);
$content = nl2br($content);
$content = ModPrince::ModBbcode($content,$t['t'['text');
echo $content;
$cached = fopen($cachefile, 'w');
fwrite($cached, $content);
fclose($cached);
}
Copy code
Nếu như bản gốc johncms thì code show bài viết nó ở trong file post.php
như này
$text = htmlentities($res['text', ENT_QUOTES, 'UTF-8');
$text = nl2br($text);
$text = bbcode::tags($text);
if ($set_user['smileys')
$text = functions::smileys($text, ($res['rights' >= 1) ? 1 : 0);
echo $text;
Copy code
$text = nl2br($text);
$text = bbcode::tags($text);
if ($set_user['smileys')
$text = functions::smileys($text, ($res['rights' >= 1) ? 1 : 0);
echo $text;
Copy code
bạn chỉ cần thay cái code này bằng code show bài viết của mình là được, thay xong nó được như thế này
file forum/includes/post.php
# Cache nội dung bài viết
$file = $_SERVER['HTTP_HOST' . $_SERVER['REQUEST_URI';
$cachefile = 'Cache/' . md5($file) . '.html';
if(file_exists($cachefile))
{
include($cachefile);
} else {
/
$text = htmlentities($res['text', ENT_QUOTES, 'UTF-8');
$text = nl2br($text);
$text = bbcode::tags($text);
if ($set_user['smileys')
$text = functions::smileys($text, ($res['rights' >= 1) ? 1 : 0);
echo $text;
$cached = fopen($cachefile, 'w');
fwrite($cached, $content);
fclose($cached);
}
Copy code
$file = $_SERVER['HTTP_HOST' . $_SERVER['REQUEST_URI';
$cachefile = 'Cache/' . md5($file) . '.html';
if(file_exists($cachefile))
{
include($cachefile);
} else {
/
$text = htmlentities($res['text', ENT_QUOTES, 'UTF-8');
$text = nl2br($text);
$text = bbcode::tags($text);
if ($set_user['smileys')
$text = functions::smileys($text, ($res['rights' >= 1) ? 1 : 0);
echo $text;
$cached = fopen($cachefile, 'w');
fwrite($cached, $content);
fclose($cached);
}
Copy code
nguyên lí của nó là đầu tiên nó tìm xem đã tồn tại file cache nội dung chưa, nếu có thì nó chèn vào nếu không nó sẽ lưu nội dung vào cache rồi show nội dung ra, thế thôi

ảnh demo:

đây là list file cache trong thư mục cache của mình, nặng tầm 23 Mb cache, thực ra cache nó sẽ cải thiện hiệu suất , giảm đáng kể các truy vấn tới mysql sever, host sẽ load nhanh hơn, nếu ai muốn mình sẽ share luôn cache cả trang, nhưng cách này không hay lắm, mình đã thử và đã bỏ

demo live ở đây nè: http://teenclub.info/yeu-la-phai-dien-cuong-ma-chiem-doat-chuong-1.html

Trực Tuyến:
Khách: 1