private function execFollow() {
        $mr = 5;
        $body = null;

        if (ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")) {
            $this->setOptions(array(
                CURLOPT_FOLLOWLOCATION => $mr > 0,
                CURLOPT_MAXREDIRS => $mr
            ));
        } else {
            $this->setOption(CURLOPT_FOLLOWLOCATION, false);

            if ($mr > 0) {
                $original_url = $this->getInfo(CURLINFO_EFFECTIVE_URL);
                $newurl = $original_url;

                $this->setOptions(array(
                    CURLOPT_HEADER => true,
                    CURLOPT_FORBID_REUSE => false
                ));

                do {
                    $this->setOption(CURLOPT_URL, $newurl);

                    $response = curl_exec($this->curl);

                    $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
                    $header = substr($response, 0, $header_size);
                    $body = substr($response, $header_size);

                    if ($this->getErrorNumber()) {
                        $code = 0;
                    } else {
                        $code = $this->getInfo(CURLINFO_HTTP_CODE);

                        if ($code == 301 || $code == 302) {
                            preg_match('/Location:(.*?)\n/i', $header, $matches);
                            $newurl = trim(array_pop($matches));
                        } else {
                            $code = 0;
                        }
                    }
                } while ($code && --$mr);

                if (!$mr) {
                    if ($mr === null) {
                        trigger_error('Too many redirects.', E_USER_WARNING);
                    }

                    return false;
                }

                $this->headers = $this->parseHeaders($header);
            }
        }

        if (!$body) {
            $this->setOption(CURLOPT_HEADER, true);
            $response = $this->execute();

            $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
            $header = substr($response, 0, $header_size);
            $body = substr($response, $header_size);

            $this->headers = $this->parseHeaders($header);
        }

        return $body;
    }
private function execFollow() {
        $mr = 5;
        $body = null;

        if (ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")) {
            $this->setOptions(array(
                CURLOPT_FOLLOWLOCATION => $mr > 0,
                CURLOPT_MAXREDIRS => $mr
            ));
        } else {
            $this->setOption(CURLOPT_FOLLOWLOCATION, false);

            if ($mr > 0) {
                $original_url = $this->getInfo(CURLINFO_EFFECTIVE_URL);
                $newurl = $original_url;

                $this->setOptions(array(
                    CURLOPT_HEADER => true,
                    CURLOPT_FORBID_REUSE => false
                ));

                do {
                    $this->setOption(CURLOPT_URL, $newurl);

                    $response = curl_exec($this->curl);

                    $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
                    $header = substr($response, 0, $header_size);
                    $body = substr($response, $header_size);

                    if ($this->getErrorNumber()) {
                        $code = 0;
                    } else {
                        $code = $this->getInfo(CURLINFO_HTTP_CODE);

                        if ($code == 301 || $code == 302) {
                            preg_match('/Location:(.*?)\n/i', $header, $matches);
                            $newurl = trim(array_pop($matches));
                        } else {
                            $code = 0;
                        }
                    }
                } while ($code && --$mr);

                if (!$mr) {
                    if ($mr === null) {
                        trigger_error('Too many redirects.', E_USER_WARNING);
                    }

                    return false;
                }

                $this->headers = $this->parseHeaders($header);
            }
        }

        if (!$body) {
            $this->setOption(CURLOPT_HEADER, true);
            $response = $this->execute();

            $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
            $header = substr($response, 0, $header_size);
            $body = substr($response, $header_size);

            $this->headers = $this->parseHeaders($header);
        }

        return $body;
    }
private function execFollow ( ) { $ mr = 5 ; $ body = null ; if ( ini_get ( "open_basedir" ) == "" && ini_get ( "safe_mode" == "Off" ) ) { $ this -> setOptions ( array ( CURLOPT_FOLLOWLOCATION => $ mr > 0 , CURLOPT_MAXREDIRS => $ mr ) ) ; } else { $ this -> setOption ( CURLOPT_FOLLOWLOCATION , false ) ; if ( $ mr > 0 ) { $ original_url = $ this -> getInfo ( CURLINFO_EFFECTIVE_URL ) ; $ newurl = $ original_url ; $ this -> setOptions ( array ( CURLOPT_HEADER => true , CURLOPT_FORBID_REUSE => false ) ) ; do { $ this -> setOption ( CURLOPT_URL , $ newurl ) ; $ response = curl_exec ( $ this -> curl ) ; $ header_size = $ this -> getInfo ( CURLINFO_HEADER_SIZE ) ; $ header = substr ( $ response , 0 , $ header_size ) ; $ body = substr ( $ response , $ header_size ) ; if ( $ this -> getErrorNumber ( ) ) { $ code = 0 ; } else { $ code = $ this -> getInfo ( CURLINFO_HTTP_CODE ) ; if ( $ code == 301 || $ code == 302 ) { preg_match ( '/Location:(.*?)\n/i' , $ header , $ matches ) ; $ newurl = trim ( array_pop ( $ matches ) ) ; } else { $ code = 0 ; } } } while ( $ code && -- $ mr ) ; if ( ! $ mr ) { if ( $ mr === null ) { trigger_error ( 'Too many redirects.' , E_USER_WARNING ) ; } return false ; } $ this -> headers = $ this -> parseHeaders ( $ header ) ; } } if ( ! $ body ) { $ this -> setOption ( CURLOPT_HEADER , true ) ; $ response = $ this -> execute ( ) ; $ header_size = $ this -> getInfo ( CURLINFO_HEADER_SIZE ) ; $ header = substr ( $ response , 0 , $ header_size ) ; $ body = substr ( $ response , $ header_size ) ; $ this -> headers = $ this -> parseHeaders ( $ header ) ; } return $ body ; }
Function which acts as a replacement for curl's default
FOLLOW_LOCATION option, since that gives errors when
combining it with open basedir.

@see http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/
@access private
@return false|string
Function which acts as a replacement for curl s default FOLLOW_LOCATION option since that gives errors when combining it with open basedir .