ใช้กับไฟล์ index.php
$getcnt = file_get_contents("404.txt");
$content_url = $_SERVER["REQUEST_URI"]."\n".$getcnt;
$exp = explode("\n",$content_url);
$uniq = array_unique($exp);
$file = fopen('404.txt', 'w');
foreach ($uniq as $url) {
if ($url != "") {
fwrite($file, $url."\n");
}
}
fclose($file);
ใช้กับไฟล์ 404.php ใน theme ที่ใช้
$block_array = array();
$geturl = file_get_contents("404.txt");
$exp = explode("\n",$geturl);
echo '<!--';
#print_r($exp);
echo '-->';
foreach ($exp as $url) {
if (($_SERVER["REQUEST_URI"] == $url) && ($url != "") && ($url != "/")){
http_response_code(404);
echo 'Not found';
echo '<meta http-equiv="refresh" content="5; url=/" />';
exit();
}
}