PHP checks whether the website can be opened normally.

Source: Internet
Author: User

PHP checks whether the website can be opened normally.

This article describes how PHP can easily check whether the website can be opened. We will share this with you for your reference. The details are as follows:

This is a PHP code that checks whether the website can be opened normally. The following code checks whether a website can be accessed normally. If it is normal, the http Status Code 200 is returned, this code can be used in many places, for example, to cache the ICO icon of a link. When caching, check whether the website is normal, if it is normal, the ICO icon is cached. Otherwise, a default icon file is called.

The Code is as follows:

<? Php/** Created on 2016-9-4 **/function httpcode ($ url) {$ ch = curl_init (); $ timeout = 3; curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt ($ ch, batch, 1); curl_setopt ($ ch, CURLOPT_HEADER, 1); curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_exec ($ ch); return $ httpcode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); curl_close ($ ch);} echo" Link to the customer's home: ". httpcode ('HTTP: // www.bkjia.com ');?> <Br/> If the value is 200, it is normal. If the value is other, it indicates it is abnormal. The value 3 after $ timeout indicates the time-out seconds.

The running effect is as follows:

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.