carlitos_way
07-08-2007, 11:16 PM
Hi all,
while trying to use AJAX remotely, after a few difficulties, a friend gave me the code that follows to make it works as a proxy. now it all works, but iwanted to know if there is any alternative to do this, and why choose one or another... a link to somegood explanation would be good enough.. thanks
<?php
$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
// Open 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, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$xml = curl_exec($session);
// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");
echo $xml;
curl_close($session);
?>
while trying to use AJAX remotely, after a few difficulties, a friend gave me the code that follows to make it works as a proxy. now it all works, but iwanted to know if there is any alternative to do this, and why choose one or another... a link to somegood explanation would be good enough.. thanks
<?php
$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
// Open 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, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$xml = curl_exec($session);
// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");
echo $xml;
curl_close($session);
?>