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: