Site monitoring php code (if there are multiple sites, just modify it slightly), you can send SMS alarm to your mobile phone_PHP tutorial

WBOY
Release: 2016-07-13 17:44:54
Original
1062 people have browsed it

For the following HTML format code, you create a new hostmonter.php file, then copy the following code into the file and save it, upload it to the server, and then use a browser or Linux timer and other tools to do it, the following code It is checked every 10 minutes. There are three domain names in the code below. Modify multiple domain names yourself:

——————————————Code content————————————




function check($host, $find)
{
$fp = fsockopen($host, 80, $errno, $errstr, 10);
If (!$fp)
{
echo “$errstr ($errno)n”;
} else
{
​​​​ $header = “GET/HTTP/1.1rn”;
$header .= “Host: $hostrn”;
$header .= “Connection: closernrn”;
          fputs($fp, $header);
         while (!feof($fp))
          {
                $str .= fgets($fp, 1024);
}
         fclose($fp);
          return (strpos($str, $find) !== false);
}
}
function ok($host)
{
/* Change the youremail@139.com below to your email address */
/* mail(’200513538@qq.com’, ‘Monitoring’, $host.’ down’); */
echo “$host – OK
”;
}

function posttohost($host)
{
/* The following is an example of the Western Digital SMS interface */
​​​​ $maildomain=’domain name’;
$mailpwd=’password’;
$sendmobile=’The mobile phone number to receive the alarm, China Unicom/Telecom 189/China Mobile can be used’;
$sendcontent=”$host failed!”;
$sendport=’3′;
if($maildomain!=””){
$key=md5($maildomain.$mailpwd);
$url=”http://usericp.west263.cn/default.aspx”;
$data=array('mobile'=>$sendmobile,'sendcontent'=>mb_convert_encoding($sendcontent, "UTF-8", "gb2312"),'port'=>$sendport,'maildomain'=> ;$maildomain,'key'=>$key);
$data=http_build_query($data);
$opts=array(‘http’=>array(‘method’=>’POST’,
‘header’=>”Content-type: application/x-www-form-urlencodedrn”.
“Content-Length:”.strlen($data).”rn”,
‘content’=>$data),);
$context=stream_context_create($opts);
$html=file_get_contents($url,false,$context);
$result=iconv(“UTF-8″,”gb2312″,$html);
if($result==”200 ok”){
echo “$host – sendOK
”;
}else{
echo “$result
”;
}


}
}
for ($i=1; $i<=3; $i++)
{
if ($i==1)
          {
/* Change the URL below to the URL you want to monitor */
          $host = ‘www.xxx.com’;
$Content = “www.xxx.com-Unable to connect”;
         }elseif ($i==2)
          {
          $host = ‘www.yyy.com’;
$Content = “www.yyy.com-Unable to connect”;
}elseif ($i==3)
          {
           $host = ‘www.zzz.com’;
$Content = “www.zzz.com-Unable to connect”;
}

/* Change the "Registration Number:" below to a special string in the source code of your website homepage */
$find = ‘Registration number:’;

if (!check($host, $find))
{
posttohost($host);
}
else
{ok($host);}

}
?>


————————————End of code——————————————

from:lonely blog

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478708.htmlTechArticleThe following html format code, you create a hostmonter.php file, then copy the following code into the file and Save, upload to the server, and then use a browser or Linux...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template