开发者

PHP image proxy breaks in PHP 5

I have this image proxy. It worked fine in PHP 4 but not that I have upgraded to 5 I get this error:

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /path/to/proxy.php on line 34

Here is line 34:

curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);

How can I fix this?

below is the whole script.

$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
$headers = ($_POST['headers']) ? $_POST['headers'] : $_GET['headers'];
$mimeType =($_POST['mimeType']) ? $_POST['mimeType'] : $_GET['mimeType'];


//Start the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['url']) {
    $postvars = '';
    while ($element = current($_POST)) {
        $postvars .= key($_POST).'='.$element.'&';
        next($_POST);
    }
    curl_setopt ($session, CURLOPT_POST, true);
    curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}


// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, ($headers == "true") ? true : false);

curl_setopt($session, CURLOPT_FOLLOWLOCATION, true); 
//curl_setopt($ch, CURLOPT_TIMEOUT, 4); 
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$response = curl_ex开发者_Python百科ec($session);


if ($mimeType != "")
{
    // The web service returns XML. Set the Content-Type appropriately
    #header("Content-Type: ".$mimeType);

    //Allmow caching
    #header('Cache-Control: public');

}

echo $response;

curl_close($session);


Apparently it can't be done. You have to work around it by examining the resultant headers for a Location header and then fetch from there instead. This is because curl will naively follow all URLs sent by a web server, including file:// URLs, which have obvious security ramifications.


You can read the error message, and check safe_mode and open_basedir.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜