Add the following code to the top of the 404.php file on the WordPress theme you are using:
If your host supports the mail () function or if you set up SMTP to send mail, in short, it is able to send mail on the line, a will go to see you set up the WordPress site administrator mailbox, you will find 404 notification mail (may be in the garbage bin), the content of the message as shown in this article map.
The code is as follows |
Copy Code |
Mail ($email, "404 Alert:". $blog. " [" . $theme. "]", $message, "from: $email"); |
Otherwise, we'll do it the following way.
The code is as follows |
Copy Code |
<?php//WP 404 ALERTS
Set status Header ("http/1.1 404 Not Found"); Header ("status:404 not Found");
Site Info $blog = Get_bloginfo (' name '); $site = get_bloginfo (' url '). '/'; $email = Get_bloginfo (' Admin_email ');
Theme Info if (!empty ($_cookie["Nkthemeswitch"). Cookiehash])) { $theme = Clean ($_cookie["Nkthemeswitch"). Cookiehash]); } else { $theme _data = Wp_get_theme (); $theme = Clean ($theme _data->name); } Referrer if (Isset ($_server[' http_referer ')) { $referer = Clean ($_server[' http_referer ']); } else { $referer = "undefined"; } Request URI if (Isset ($_server[' Request_uri ')) && isset ($_server["Http_host"])) { $request = Clean (' http://' $_server["Http_host"]. $_server["Request_uri"]); } else { $request = "undefined"; } Query string if (Isset ($_server[' query_string ')) { $string = Clean ($_server[' query_string ']); } else { $string = "undefined"; } IP Address if (Isset ($_server[' remote_addr ')) { $address = Clean ($_server[' remote_addr ']); } else { $address = "undefined"; } User Agent if (Isset ($_server[' http_user_agent ')) { $agent = Clean ($_server[' http_user_agent ']); } else { $agent = "undefined"; } Identity if (Isset ($_server[' remote_ident ')) { $remote = Clean ($_server[' remote_ident ']); } else { $remote = "undefined"; } Log Time $time = Clean (date ("F JS Y, H:ia", Time ());
Sanitize function Clean ($string) { $string = RTrim ($string); $string = LTrim ($string); $string = Htmlentities ($string, ent_quotes); $string = Str_replace ("n", "<br>", $string); if (GET_MAGIC_QUOTES_GPC ()) { $string = Stripslashes ($string); } return $string; }
$message = "Time:". $time. "N". "* 404:". $request. "N". "SITE:". $site. "N". "THEME:". $theme. "N". "Referrer:". $referer. "N". "QUERY STRING:". $string. "N". "REMOTE Address:". $address. "N". "REMOTE IDENTITY:". $remote. "N". "USER AGENT:". $agent. "NNN";
Mail ($email, "404 Alert:". $blog. " [" . $theme. "]", $message, "from: $email");
?> |