时间:2021-07-01 10:21:17 帮助过:28人阅读
$url = ‘http://www.baidu.com';
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
if(false == $contents)
{
echo ‘Curl error: ‘ . curl_error($ch);
}
else
{
….
}
代码如下:
curl_getinfo($ch, CURLINFO_HTTP_CODE);
以上就介绍了电信断网 PHP下判断网址是否有效的代码,包括了电信断网方面的内容,希望对PHP教程有兴趣的朋友有所帮助。