Home Backend Development PHP Tutorial PHP simulates the return status of post_verification page (explanation with examples)_PHP tutorial

PHP simulates the return status of post_verification page (explanation with examples)_PHP tutorial

Jul 13, 2016 am 10:25 AM
php

1. Main file, visit this page, which sets the return status of this file based on the return result of the "Verification Page" header('HTTP/1.1 '.$code.' '.$_status[$code ])

Copy code The code is as follows:

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); //设置URL

        curl_setopt($curl, CURLOPT_HEADER, 1); //获取Header
        curl_setopt($curl,CURLOPT_NOBODY,true); //Body就不要了吧,我们只是需要Head
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //数据存到成字符串吧,别给我直接输出到屏幕了
        $data = curl_exec($curl); //开始执行啦~
        $HttpCode =curl_getinfo($curl,CURLINFO_HTTP_CODE); //我知道HTTPSTAT码哦~
        curl_close($curl); //用完记得关掉他
        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 "开始时间".$sTime."
";
            echo "检测结果
";
            for($i=$start;$i<=$end;$i++)
{
$url=ResetUrl($UrlArr[$i]);
$state=GetStatusCode($url);
echo " ".$state ." => ".$url."";
                if($state!="200")
                {
                    echo " 本条访问出错!
";
                    send_http_status($state);

                    //发邮件
                    require("Mail.php");
                    $MailPara["Subject"]="网站监控结果";
                    $MailPara["Body"]="错误信息:状态->".$state."
地址:".$url;
                    SendResultMail($MailPara);

                                                                                                               =date("Y/m/d H:m:s");

               echo "End time".$eTime."
";
      }

}

ShowStateInfo($UrlArr,$MailPara);
?>



2. Mail



Copy code
The code is as follows:function SendResultMail($MailPara) {
require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();
CharSet = $MailPara["CharSet"];
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())
."
";
                           exit;                                                            

              echo "Email sent successfully
";

   }



3. Configuration file



Copy code


The code is as follows:

$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"
);

//Send related information via email
$MailPara=array(
"CharSet"=> "GB2312",
"Host"=> "smtp.exmail.qq.com", / / Email service address
"Port"=>25,

"FromMail"=> "fdsafdsafd@fdasfds.com", // Sender's email address
"FromMailPassword"=> "*********", // Sender Email password
"FromMailName"=> "Detection", "To"=>array(
"ToMail"= >" defdafdsafdsafdf@qq.com", "ToMailName"=> "bqq", //Recipient's name
),
array(
"ToMail"= >"abfdsafdsafdsafc@gmail.com", "ToMailName"=> "agmail", "ToMailName"=> "agmail", "ToMailName" 🎜>
"Subject"=> "", "Subject"                                             " //Additional information, You can omit it
);

?>


The email mainly uses "phpmailer",

Click to download




http://www.bkjia.com/PHPjc/824912.html

www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/824912.html

TechArticle

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles