php simulates the return status of post_ to verify that the of instance explains

  • 2020-10-23 20:55:02
  • OfStack

1. Main file, visit the page that sets the return status of the file header('HTTP/1.1 '.$code.'.$_status[$code]) according to the return result of the "Validation Page"


<?php
    ini_set('max_execution_time', 120);
    include("CheckConfig.php");
    function send_http_status($code) {
        static $_status = array(
        // Informational 1xx
=> 'Continue',
=> 'Switching Protocols',
        // Success 2xx
=> 'OK',
=> 'Created',
=> 'Accepted',
=> 'Non-Authoritative Information',
=> 'No Content',
=> 'Reset Content',
=> 'Partial Content',
        // Redirection 3xx
=> 'Multiple Choices',
=> 'Moved Permanently',
=> 'Moved Temporarily ',  // 1.1
=> 'See Other',
=> 'Not Modified',
=> 'Use Proxy',
        // 306 is deprecated but reserved
=> 'Temporary Redirect',
        // Client Error 4xx
=> 'Bad Request',
=> 'Unauthorized',
=> 'Payment Required',
=> 'Forbidden',
=> 'Not Found',
=> 'Method Not Allowed',
=> 'Not Acceptable',
=> 'Proxy Authentication Required',
=> 'Request Timeout',
=> 'Conflict',
=> 'Gone',
=> 'Length Required',
=> 'Precondition Failed',
=> 'Request Entity Too Large',
=> 'Request-URI Too Long',
=> 'Unsupported Media Type',
=> 'Requested Range Not Satisfiable',
=> 'Expectation Failed',
        // Server Error 5xx
=> 'Internal Server Error',
=> 'Not Implemented',
=> 'Bad Gateway',
=> 'Service Unavailable',
=> 'Gateway Timeout',
=> 'HTTP Version Not Supported',
=> 'Bandwidth Limit Exceeded'
        );
        if(array_key_exists($code,$_status)) {
            header('HTTP/1.1 '.$code.' '.$_status[$code]);
        }
    }
    function GetStatusCode($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url); // Set up the URL

        curl_setopt($curl, CURLOPT_HEADER, 1); // To obtain Header
        curl_setopt($curl,CURLOPT_NOBODY,true); //Body No, we just need it Head
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Save the data as a string, and don't output it directly to the screen 
        $data = curl_exec($curl); // It's time to execute 
        $HttpCode =curl_getinfo($curl,CURLINFO_HTTP_CODE); // I know that HTTPSTAT Code oh ~ 
        curl_close($curl); // Turn it off when you're done 
        return $HttpCode;
    }
    function ResetUrl($url)
    {
        if(strpos($url,"?")>0)
            $url.="&rnd";
        else
            $url.="?rnd";
        $url.=rand();
        return $url;
    }
    function ShowStateInfo($UrlArr,$MailPara)
    {
        $count=count($UrlArr);
        if(isset($_REQUEST["start"]))
        {
            $start=$_REQUEST["start"]*1;
        }
        else
        {
            $start=1;
        }
        if(isset($_REQUEST["end"]))
        {
            $end=$_REQUEST["end"]*1;
        }
        else
        {
            $end=$start;
        }
        $start=$start-1;
        $end=$end-1;
        if($start<0)
        {
            $start=0;
        }
        if($start>=0 && $start<$count)
        {
            if($end>=$count)
            {
                $end=$count-1;
            }
            if($end<$start)
            {
                $end=$start;
            }
            $sTime=date("Y/m/d H:m:s");
            echo " The start time ".$sTime."<br/>";
            echo " Test results <br />";
            for($i=$start;$i<=$end;$i++)
            {
                $url=ResetUrl($UrlArr[$i]);
                $state=GetStatusCode($url);
                echo "&nbsp;&nbsp;".$state ."&nbsp;=>&nbsp;<a href='http://".$url."' target='_blank'>".$url."<a>";
                if($state!="200")
                {
                    echo " <span style='color:red;font-weight:bold'> This article access error! </span><br/>";
                    send_http_status($state);
                    // email 
                    require("Mail.php");
                    $MailPara["Subject"]=" Website monitoring results ";
                    $MailPara["Body"]=" Error message: Status -><span style='color:red;font-weight:bold'>".$state."</span><br/> Address: ".$url;
                    SendResultMail($MailPara);
                    break;
                }
                echo "<br/>";
            }
            $eTime=date("Y/m/d H:m:s");
            echo " The end of time ".$eTime."<br/>";
        }
    }
    ShowStateInfo($UrlArr,$MailPara);
?>

2. Email

function SendResultMail($MailPara)
    {
        require("phpmailer/class.phpmailer.php"); 
        $mail = new PHPMailer(); 
        $mail->CharSet = $MailPara["CharSet"];
        $mail->IsSMTP();
        $mail->Host = $MailPara["Host"]; 
        $mail->Port = $MailPara["Port"];
        $mail->SMTPAuth = true; 
        $mail->Username = $MailPara["FromMail"];
        $mail->Password = $MailPara["FromMailPassword"];
        $mail->From = $MailPara["FromMail"]; 
        $mail->FromName = $MailPara["FromMailName"];
        foreach($MailPara["To"] as $toMail)
        {
            $mail->AddAddress($toMail["ToMail"], $toMail["ToMailName"]);
        }
        $mail->Subject = $MailPara["Subject"]; 
        $mail->Body = $MailPara["Body"]; 
        $mail->AltBody = $MailPara["AltBody"]; 
        if(!$mail->Send())
        {
            echo " Email failed to send . <p>";
            echo " The reason for the error : " . $mail->ErrorInfo ."<br/>";
            exit;
        }
        echo " Email sent successfully <br/>";
    }

3. Configuration files

<?php
    $UrlArr=array(
        "localhost/test/281892.shtml",
        "localhost/test/all-229-1-221.shtml",
        "localhost/testclass/all-254-1-1.shtml",
        "localhost/test/cheng/bd/1988478.html",
        "localhost/test/asd/2066495.html"
    );
    // Email to send relevant information 
    $MailPara=array(
        "CharSet"=> "GB2312",
        "Host"=> "smtp.exmail.qq.com",            //  Email Service Address 
        "Port"=>25,
        "FromMail"=> "fdsafdsafd@fdasfds.com",    //  E-mail address of sender 
        "FromMailPassword"=> "*********", //  Sender email password 
        "FromMailName"=> " detection ",            // Address of sender 

        "To"=>array(
            array(
                "ToMail"=>"defdafdsafdsafdf@qq.com",        // Recipient email Address 
                "ToMailName"=> "bqq",            // Address of addressee 
            ),
            array(
                "ToMail"=>"abfdsafdsafdsafc@gmail.com",        // Recipient email Address 
                "ToMailName"=> "agmail",            // Address of addressee 
            )
        ),
        "Subject"=> "",                // Email title 
        "Body"=> "",            // Email content 
        "AltBody"=> " Additional information "                // Additional information that can be omitted         
    );
?>

The email mainly USES "phpmailer", click to download


Related articles: