PHP+;卷曲不起作用

PHP+;卷曲不起作用,php,curl,Php,Curl,尝试使用cURL和PHP获取某个URL的内容。 该代码应该在sourceforge.net project web托管服务器上运行 代码: 我已经检查了cURL是否受支持。但是上面的代码不起作用,页面一直加载到超时,没有输出。我也尝试过编码的url。为什么? 错误503服务不可用。PHP 5.3.2版我用你的curl代码替换了我的curl代码,但它不起作用。我试过使用“gmail.com”,结果显示我的代码很好,而你的代码出现了“301移动”错误 我的代码如下: function get_w

尝试使用cURL和PHP获取某个URL的内容。 该代码应该在sourceforge.net project web托管服务器上运行

代码:


我已经检查了cURL是否受支持。但是上面的代码不起作用,页面一直加载到超时,没有输出。我也尝试过编码的url。为什么?


错误
503服务不可用
。PHP 5.3.2版

我用你的curl代码替换了我的curl代码,但它不起作用。我试过使用“gmail.com”,结果显示我的代码很好,而你的代码出现了“301移动”错误

我的代码如下:

function get_web_page($url)
{
        //echo "curl:url<pre>".$url."</pre><BR>";
    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "spider", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 15,      // timeout on connect
        CURLOPT_TIMEOUT        => 15,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects

    );

    $ch      = curl_init($url);
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch,CURLINFO_EFFECTIVE_URL );
    curl_close( $ch );

    $header['errno']   = $err;
    $header['errmsg']  = $errmsg;

    //change errmsg here to errno
    if ($errmsg)
    {
        echo "CURL:".$errmsg."<BR>";
    }
    return $content;
}
函数获取网页($url)
{
//回显“curl:url”。$url.
”; $options=array( CURLOPT_RETURNTRANSFER=>true,//返回网页 CURLOPT_HEADER=>false,//不返回头 CURLOPT_FOLLOWLOCATION=>true,//跟随重定向 CURLOPT_ENCODING=>“”,//处理所有编码 CURLOPT_USERAGENT=>“蜘蛛”//我是谁 CURLOPT_AUTOREFERER=>true,//在重定向时设置referer CURLOPT_CONNECTTIMEOUT=>15,//连接超时 CURLOPT_TIMEOUT=>15,//响应超时 CURLOPT_MAXREDIRS=>10,//在10次重定向后停止 ); $ch=curl\u init($url); curl_setopt_数组($ch$options); $content=curl\u exec($ch); $err=curl\u errno($ch); $errmsg=curl\u error($ch); $header=curl\u getinfo($ch,CURLINFO\u有效\u URL); 卷曲关闭($ch); $header['errno']=$err; $header['errmsg']=$errmsg; //将此处的errmsg更改为errno 如果($errmsg) { 回声“CURL:.$errmsg.
”; } 返回$content; }
您可能希望使用文件获取内容

$content = file_get_contents('textfile.txt');
您还可以在文件内容中设置文件,例如:

有关函数的更多信息

我在使用cUrl时注意到的一些信息:


使用cUrl时,我还注意到一件事,即当URL包含http或https时,它的工作方式不同。您需要确保您的代码能够处理此问题

您遇到了什么错误?它可能来自您的Internet连接。您的代码适用于简单的html站点,但不适用于google和gmail!它们只是示例站点,我想做的是获取php文件的输出!在使用cUrl时,我还注意到,当URL从http重定向到https时,它的工作方式不同。您需要确保您的代码能够处理此问题
$content = file_get_contents('http://www.google.com');
/some code here if needed/
return $content;
$content = file_get_contents('textfile.txt');