WordPress自动记录404死链方法+实用代码
WordPress自动将404死链记录到TXT文档中
在网站根目录新建文件: 404.txt,并设置权限为:755
将以下代码粘贴到你的 WordPress 主题中的 404.php
$error_url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$error_log = "404.txt";
$entries = file($error_log);
$check=true;
foreach($entries as $f){
if($f == $error_url."\n")
$check = false;
}
if($check){
$fp = fopen($error_log,"a");
flock ($fp, LOCK_EX) ;
fwrite ($fp, $error_url."\n");
flock ($fp, LOCK_UN);
fclose ($fp);
}