php curl与CURLOPT_FOLLOWLOCATION错误

前端之家收集整理的这篇文章主要介绍了php curl与CURLOPT_FOLLOWLOCATION错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有错误

CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in

我谷歌很多解决方案,但与这个网站,他们不工作.只需要CURLOPT_FOLLOWLOCATION.愚蠢的主持人不想启用safe_mode或open_basedir.我可以自己启用它们,可以用一些参数创建htaccess?

错误表示safe_mode或open_basedir ARE已启用(可能是open_basedir),如果您的主机有任何体面的安全设置,您可能无法重写.

所以你有选择

1)改变主持人(不可想象我想象)

2)使用类似于在PHP curl_setopt页面上找到的函数,即http://www.php.net/manual/en/function.curl-setopt.php#95027

以下是第2点中指定的功能的固定版本

function curl_redirect_exec($ch,&$redirects,$curlopt_header = false) {
    curl_setopt($ch,CURLOPT_HEADER,true);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

    $data = curl_exec($ch);

    $http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    if ($http_code == 301 || $http_code == 302) {
        list($header) = explode("\r\n\r\n",$data,2);

        $matches = array();
        preg_match("/(Location:|URI:)[^(\n)]*/",$header,$matches);
        $url = trim(str_replace($matches[1],"",$matches[0]));

        $url_parsed = parse_url($url);
        if (isset($url_parsed)) {
            curl_setopt($ch,CURLOPT_URL,$url);
            $redirects++;
            return curl_redirect_exec($ch,$redirects,$curlopt_header);
        }
    }

    if ($curlopt_header) {
        return $data;
    } else {
        list(,$body) = explode("\r\n\r\n",2);
        return $body;
    }
}

猜你在找的PHP相关文章