脚本宝典收集整理的这篇文章主要介绍了php – 我想在此cURL代码中检查网站是否存在?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$ch = curl_init('http://domain.COM/curl.@R_301_2493@'); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); curl_setopt($ch,CURLOPT_RETURNtransfer,true); $result = curl_exec($ch); curl_close($ch); if (!$result) // IT will execute some codes if there is no result echoed From curl.@R_301_2493@
function check_alive($url,$timeout = 10) { $ch = curl_init($url); // Set request options curl_setopt_array($ch,array( CURLOPT_FOLLOWLOCATION => true,CURLOPT_NOBODY => true,CURLOPT_TIMEOUT => $timeout,CURLOPT_USERAGENT => "page-check/1.0" )); // Execute request curl_exec($ch); // Check if an error occurred if(curl_errno($ch)) { curl_close($ch); return false; } // Get HTTP response code $code = curl_getinfo($ch,CURLINFO_HTTP_CODE); curl_close($ch); // Page is alive if 200 OK is received return $code === 200; }
以上是脚本宝典为你收集整理的php – 我想在此cURL代码中检查网站是否存在?全部内容,希望文章能够帮你解决php – 我想在此cURL代码中检查网站是否存在?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。