Curl-php determines whether a website can be opened

Source: Internet
Author: User
I want to determine whether a website can be opened. use the phpping website to check whether ping is successful. 2. whether the http return is 200Ok3. is there any html tag in the file content? I don't know how to implement it in step 3. I just want to use file_get_content and find out if there is any html in the file ?... I want to determine whether a website can be opened
1. ping the website using php to check whether the website can be pinged.
2. whether the http return result is 200Ok
3. whether the file content contains html tags
At present, I don't know how to implement the third step. it's file_get_content. then I can find out if there is any html in this file?
Use strpos?

Reply content:

I want to determine whether a website can be opened
1. ping the website using php to check whether the website can be pinged.
2. whether the http return result is 200Ok
3. whether the file content contains html tags
At present, I don't know how to implement the third step. it's file_get_content. then I can find out if there is any html in this file?
Use strpos?


  

If a jump like 302 is counted as successful access, you can add it to the judgment.

If ($ curl_code = 200 | $ curl_code = 302) {echo 'connection successful, status code :'. $ curl_code;} else {echo 'connection failed, status code :'. $ curl_code ;}

http://www.baidu.com/The returned value is 200;
http://www.baidu.com/xxxThe returned result is 302, which is being accessed,http://www.baidu.com/xxxJumphttps://www.baidu.com/search/error.htmlThis is the case.

I think you can get the file content first to determine whether html tags exist! There is nothing to worry about.

curlSimulate a visit and check whether the returned value is correct.

Curl determines whether http status is 200

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.