I have a working cURL function that allows me to bypass the Cross Domain issue, this is the code below
<?php
$url = "http://explorerapi.barratthomes.co.uk/v2.0/development/getbyitemkey?ItemKey=H618701&Auth.Utc=2015-07-31T08:30:26.761Z&Auth.RequestId=a22a17d8-8d62-4954-8a9c-79e5c244c308&Auth.DeviceId=23a5bb10-c646-47c4-8fda-1b6f1d528de3&Auth.Hash=052DAA8E425F143D4B5C55A1EAC87C5D&BrandCode=BAR&ApplicationId=ApplicationId&ApplicationVersion=1.2.3.4&LanguageCode=en-gb&IsPublished=true&MarketingSuiteDevelopmentId=MarketingSuiteDevelopmentId&UserLocation=UserLocation&Os=Android&ScreenResolution=1024x768&Hierarchical=True";
$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, $url);
curl_setopt($cu, CURLOPT_HEADER, false);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cu, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($cu, CURLOPT_CONNECTTIMEOUT, 10);
$result = curl_exec($cu);
if(curl_errno($cu))
{
echo "<h2>Unable to connect to site</h2>";
}
curl_close($cu);
echo $result;
?>
This works fine when I set the url as seen here. However The url is dynamic and is different each time, therefore I have a JavaScript file which creates the URL and puts it into a variable.
I am having trouble getting the JavaScript variable into PHP so I can use the URL. I have been trying with $_GET and $_POST but having no luck.
Here is my Java for reference the address variable is coming from my JavaScript file that creates the URL.
<!DOCTYPE>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/auth.js" type="text/javascript"></script>
<meta charset="UTF-8">
</head>
<body>
<script type='text/javascript'>
var url = address;
$(document).ready(function() {
window.location.href = "test.php?url_=" + url;
$.ajax({
url: "http://127.0.0.1:4001/Barratt/test.php",
//dataType: 'json',
//method: 'GET',
//contentType: 'application/json'
})
.done(function(data) {
console.log(data);
//var response = $.parseJSON(data.contents);
$('#value').html(data);
})
.fail(function() {
alert('failed to fetch data')
});
});
</script>
<div style="width: 100%; height: 100%; border: 2px solid red;" id="value">
</div>
</body>
</html>