开发者

accept remote domain get/post request

开发者 https://www.devze.com 2023-02-08 03:32 出处:网络
I am working on a linux server that doesn\'t accept requests(get/post) remote domains. Like, if I use a form on another domain and post that to a script on this server, it isn\'t processing it. I like

I am working on a linux server that doesn't accept requests(get/post) remote domains. Like, if I use a form on another domain and post that to a script on this server, it isn't processing it. I like to know what options I will have to enable to get this done so that it accepts remote reques开发者_运维技巧ts please? is it something in the php.ini?

Regards


If the webserver blocks the posts via referrer, you would need to find a way to send a referrer from your web site. Sending the post to a script first and from there to your site would give you the possibility to fake the referrer request header.

The following code of an example php proxy is borrowed from here: 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);

?>
0

精彩评论

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