Request.Forward에 대한 속임수는 당신이 원하는 동작에 대해 깨끗하고 새로운 요청을한다는 것입니다. 따라서 현재 요청의 잔류 물이 없습니다. 예를 들어, $ _SERVER [ 'REQUEST_URI']의 java eq에 의존하는 스크립트에는 아무런 문제가 없습니다.
당신은 단지 CURL 클래스에 드롭이 할 수있는 간단한 기능을 쓸 수있다 :
<?php
/**
* CURLHandler handles simple HTTP GETs and POSTs via Curl
*
* @author SchizoDuckie
* @version 1.0
* @access public
*/
class CURLHandler
{
/**
* CURLHandler::Get()
*
* Executes a standard GET request via Curl.
* Static function, so that you can use: CurlHandler::Get('http://www.google.com');
*
* @param string $url url to get
* @return string HTML output
*/
public static function Get($url)
{
return self::doRequest('GET', $url);
}
/**
* CURLHandler::Post()
*
* Executes a standard POST request via Curl.
* Static function, so you can use CurlHandler::Post('http://www.google.com', array('q'=>'belfabriek'));
* If you want to send a File via post (to e.g. PHP's $_FILES), prefix the value of an item with an @ !
* @param string $url url to post data to
* @param Array $vars Array with key=>value pairs to post.
* @return string HTML output
*/
public static function Post($url, $vars, $auth = false)
{
return self::doRequest('POST', $url, $vars, $auth);
}
/**
* CURLHandler::doRequest()
* This is what actually does the request
* <pre>
* - Create Curl handle with curl_init
* - Set options like CURLOPT_URL, CURLOPT_RETURNTRANSFER and CURLOPT_HEADER
* - Set eventual optional options (like CURLOPT_POST and CURLOPT_POSTFIELDS)
* - Call curl_exec on the interface
* - Close the connection
* - Return the result or throw an exception.
* </pre>
* @param mixed $method Request Method (Get/ Post)
* @param mixed $url URI to get or post to
* @param mixed $vars Array of variables (only mandatory in POST requests)
* @return string HTML output
*/
public static function doRequest($method, $url, $vars=array(), $auth = false)
{
$curlInterface = curl_init();
curl_setopt_array ($curlInterface, array(
CURLOPT_URL => $url,
CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION =>1,
CURLOPT_HEADER => 0));
if (strtoupper($method) == 'POST')
{
curl_setopt_array($curlInterface, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($vars))
);
}
if($auth !== false)
{
curl_setopt($curlInterface, CURLOPT_USERPWD, $auth['username'] . ":" . $auth['password']);
}
$result = curl_exec ($curlInterface);
curl_close ($curlInterface);
if($result === NULL)
{
throw new Exception('Curl Request Error: '.curl_errno($curlInterface) . " - " . curl_error($curlInterface));
}
else
{
return($result);
}
}
}
그냥 class.CURLHandler.php이 덤프하고이 수행 할 수 있습니다 사용, 당연히
을 $ _REQUEST는 실제로 안전하지 않습니다 ($ _SERVER [ 'REQUEST_METHOD']를 확인해야합니다).
<?php
include('class.CURLHandler.php');
die CURLHandler::doRequest($_SERVER['REQUEST_METHOD'], 'http://server/myaction', $_REQUEST);
?>
은 당연히, CURL 사방을 를 설치하지거야하지만 우리는 당신이 또한 후 공정을 출력을 잡을 수 있기 때문에 이것은 당신에게 Request.Forward보다 더 많은 유연성을 제공, 또한
native PHP curl emulators for that. 있어요.
그 방법에는 많은 문제가 있습니다. 하나는 헤더를 따라 전달되지 않으며 GET 유형 요청으로 만 작동합니다. – troelskn
그리고 PHP가 안전 모드에서 실행되고 있다면 비참하게 실패 할 것입니다 ... – SchizoDuckie
... 아직 받아 들여집니다 : D –