Post 覆盖信用卡的CURLOPT_FOLLOWLOCATION

Post 覆盖信用卡的CURLOPT_FOLLOWLOCATION,post,curl,php,credit-card,Post,Curl,Php,Credit Card,我在一个共享服务器上托管了一个网站,其中设置了“open_basedir”。。。因此,信用系统会抛出一个错误,不会向买家的信用卡收费 错误消息 警告:curl_setopt()[function.curl setopt]:处于安全模式或在中设置了打开的\u basedir时,无法激活CURLOPT\u FOLLOWLOCATION 代码 在不访问根PHP.ini和切换主机的情况下,是否存在这种情况?谢谢。无法覆盖php.ini中的open\u basedir的值,因为这会有点违背目的。另一种方法

我在一个共享服务器上托管了一个网站,其中设置了“open_basedir”。。。因此,信用系统会抛出一个错误,不会向买家的信用卡收费

错误消息 警告:curl_setopt()[function.curl setopt]:处于安全模式或在中设置了打开的\u basedir时,无法激活CURLOPT\u FOLLOWLOCATION

代码
在不访问根PHP.ini和切换主机的情况下,是否存在这种情况?谢谢。

无法覆盖
php.ini
中的
open\u basedir
的值,因为这会有点违背目的。另一种方法是编写自己的函数,在未设置
open\u basedir
的情况下执行与
CURLOPT\u FOLLOWLOCATION
相同的功能。我使用了这段代码的一个变体,它循环您的请求,并在响应头中对
位置:
进行正则表达式匹配,根据需要对新请求执行以下操作:

function curl_exec_follow(/*resource*/ $ch, /*int*/ &$maxredirect = null) { 
    $mr = $maxredirect === null ? 5 : intval($maxredirect); 
    if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) { 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0); 
        curl_setopt($ch, CURLOPT_MAXREDIRS, $mr); 
    } else { 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 
        if ($mr > 0) { 
            $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 

            $rch = curl_copy_handle($ch); 
            curl_setopt($rch, CURLOPT_HEADER, true); 
            curl_setopt($rch, CURLOPT_NOBODY, true); 
            curl_setopt($rch, CURLOPT_FORBID_REUSE, false); 
            curl_setopt($rch, CURLOPT_RETURNTRANSFER, true); 
            do { 
                curl_setopt($rch, CURLOPT_URL, $newurl); 
                $header = curl_exec($rch); 
                if (curl_errno($rch)) { 
                    $code = 0; 
                } else { 
                    $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); 
                    if ($code == 301 || $code == 302) { 
                        preg_match('/Location:(.*?)\n/', $header, $matches); 
                        $newurl = trim(array_pop($matches)); 
                    } else { 
                        $code = 0; 
                    } 
                } 
            } while ($code && --$mr); 
            curl_close($rch); 
            if (!$mr) { 
                if ($maxredirect === null) { 
                    trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING); 
                } else { 
                    $maxredirect = 0; 
                } 
                return false; 
            } 
            curl_setopt($ch, CURLOPT_URL, $newurl); 
        } 
    } 
    return curl_exec($ch); 
} 

“我在共享服务器上托管……不会向买家的信用卡收费”恭喜,你违反了PCI:-/让我休息一下,伙计,我会搞定的,还没直播呢。
function curl_exec_follow(/*resource*/ $ch, /*int*/ &$maxredirect = null) { 
    $mr = $maxredirect === null ? 5 : intval($maxredirect); 
    if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) { 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0); 
        curl_setopt($ch, CURLOPT_MAXREDIRS, $mr); 
    } else { 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 
        if ($mr > 0) { 
            $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 

            $rch = curl_copy_handle($ch); 
            curl_setopt($rch, CURLOPT_HEADER, true); 
            curl_setopt($rch, CURLOPT_NOBODY, true); 
            curl_setopt($rch, CURLOPT_FORBID_REUSE, false); 
            curl_setopt($rch, CURLOPT_RETURNTRANSFER, true); 
            do { 
                curl_setopt($rch, CURLOPT_URL, $newurl); 
                $header = curl_exec($rch); 
                if (curl_errno($rch)) { 
                    $code = 0; 
                } else { 
                    $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); 
                    if ($code == 301 || $code == 302) { 
                        preg_match('/Location:(.*?)\n/', $header, $matches); 
                        $newurl = trim(array_pop($matches)); 
                    } else { 
                        $code = 0; 
                    } 
                } 
            } while ($code && --$mr); 
            curl_close($rch); 
            if (!$mr) { 
                if ($maxredirect === null) { 
                    trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING); 
                } else { 
                    $maxredirect = 0; 
                } 
                return false; 
            } 
            curl_setopt($ch, CURLOPT_URL, $newurl); 
        } 
    } 
    return curl_exec($ch); 
}