Php 存在简单的卷曲url';行不通
我有两个用PHP编写的代码Php 存在简单的卷曲url';行不通,php,http,curl,Php,Http,Curl,我有两个用PHP编写的代码 <?php error_reporting(1); function url_exists($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); curl_
<?php
error_reporting(1);
function url_exists($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$status = array();
preg_match('/HTTP\/.* ([0-9]+) .*/', curl_exec($ch) , $status);
return ($status[1] == 200);
}
echo "EX:".url_exists("http://www.google.com");
?>
及
以上这些都不行吗?为什么?昨天效果不错,为什么有些时候PHP无法解释
我在php.ini上有一个curl扩展。。。我试过3台不同的服务器
我做错了什么?多谢各位
echo "EX:".url_exists("http://www.google.com");
将始终回显EX:
,因为url\u存在
返回布尔值。尝试:
echo "EX:" . (url_exists("http://www.google.com") ? 'true' : 'false');
也许这样行吗
$ch = curl_init("http://www.example.com/favicon.ico");
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// $retcode > 400 -> not found, $retcode = 200, found.
curl_close($ch);
来源什么不起作用?错误消息?什么都没有,只是不会返回1或0。。。相信我,如果google.com不存在的话,你的任何脚本都会返回1或0!请谷歌“js调试”。尝试
var_dump(curl_exec($ch))代码>。另请参阅下面我对echo布尔值的编辑。第二个代码的var_dump(curl_exec($ch))返回bool(false)。。。天啊,这太令人沮丧了,昨天工作得很好,我从来没有碰过电脑,我已经安装了deepfreeze…第二个代码呢?它每次都返回“notfound”,不管我在那里放了什么链接,这就是我调试的意思<代码>echo$httpcode代码>=>'302',谷歌httpcode 302=>重定向,谷歌curl follow重定向=>是的,你是对的,它返回了302,谢谢,我放了一些whare trim()来解决这个问题。。。哦php有时会很难,关于这一点,请遵循重定向,您只需写一行,witch我不需要,但谢谢
$ch = curl_init("http://www.example.com/favicon.ico");
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// $retcode > 400 -> not found, $retcode = 200, found.
curl_close($ch);