接受远程域get / post请求

时间:2011-02-01 18:50:17

标签: php apache

我正在开发一个不接受请求(获取/发布)远程域的Linux服务器。就像,如果我在另一个域上使用表单并将其发布到此服务器上的脚本,则不会对其进行处理。我想知道我必须启用哪些选项才能完成此操作以便它接受远程请求?它是php.ini中的东西吗?

此致

1 个答案:

答案 0 :(得分:2)

如果网络服务器通过引荐来源阻止帖子,您需要找到一种从您的网站发送引荐来源的方法。首先将帖子发送到脚本并从那里发送到您的站点将使您可以伪造引用者请求标头。

从这里借用以下代码的PHP代理:http://snipplr.com/view/16058/php-url-proxy/

<?php
// PHP Proxy
// Responds to both HTTP GET and POST requests
//
// Author: Abdul Qabiz
// March 31st, 2006
//

// Get the url of to be proxied
// Is it a POST or a GET?
$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_exec($session);

// NOTE: HERE YOU WILL OVERRIDE THE REFERRER REQUEST HEADER
if ($mimeType != "")
{
// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: ".$mimeType);
}

echo $response;

curl_close($session);

?>