braican
1/5/2015 - 8:42 PM

proxy for ajax

proxy for ajax

<?php

function strip_cdata($string) {   
    preg_match_all('/<!\[cdata\[(.*?)\]\]>/is', $string, $matches);
    return str_replace($matches[0], $matches[1], $string);
}

$ch = curl_init();
$url = $_GET['url'];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);

$result = curl_exec($ch);

curl_close($ch);

$stripped = strip_cdata($result);

$decode = html_entity_decode($stripped);

echo $decode;

/*

javascript (jquery ajax) usage:

$.ajax({
  url: 'PATH/TO/PROXY/proxy.php',
  data: {
    url: action + '?' + submitData
  },
  error: ajaxError,
  success: function(data, textStatus, jqxhr) {
    console.log(data);
  },
});

*/