加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php curl与CURLOPT_FOLLOWLOCATION错误

发布时间:2020-12-13 16:40:57 所属栏目:PHP教程 来源:网络整理
导读:我有错误 CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in 我谷歌很多解决方案,但与这个网站,他们不工作.只需要CURLOPT_FOLLOWLOCATION.愚蠢的主持人不想启用safe_mode或open_basedir.我可以自己启用它
我有错误

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("rnrn",$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("rnrn",2);
        return $body;
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读