0

Add below script in 404.php file

// site info
$blog  = get_bloginfo('name');
$site  = get_bloginfo('url') . '/';
$email = get_bloginfo('admin_email');
 // theme info
if (!empty($_COOKIE["c2code" . COOKIEHASH])) {
 $theme = clean($_COOKIE["c2code" . 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    . "<br>" . 
 "*404: "            . $request . "<br>" . 
 "SITE: "            . $site    . "<br>" . 
 "REFERRER: "        . $referer . "<br>" . 
 "QUERY STRING: "    . $string  . "<br>" . 
 "REMOTE ADDRESS: "  . $address . "<br>" . 
 "USER AGENT: "      . $agent   . "<br><br><br>";
$headers = array('Content-Type: text/html; charset=UTF-8');
if($string=='q=/cohort3'){
 //echo 'mail'.$message;
 wp_mail( $email, "404 Alert: " . $blog , $message, $headers );
 }

Jagdish Sarma Asked question March 9, 2023
Add a Comment