The very first: I'm using Firebug add-on and see what happen
Here one ajax get content from other site
We have this link
https://apis.pos.com.my/apigateway/as2corporate/api/v2trackntracewebapijson/v1/?id=EP024922993MY&Culture=En
In request of header we can see require X-User-Key

Now we must find X-User-Key => We can view source

Now we build source code
<?php
function _curl($url,$post="",$usecookie = false,$_sock = false,$timeout = false,$x_user_key = false) {
$ch = curl_init();
if($post) {
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
}
if($timeout){
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,$timeout);
}
if($_sock){
curl_setopt($ch, CURLOPT_PROXY, $_sock);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12'
));
if($x_user_key){
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-User-Key: '.$x_user_key,
'Referer: http://poslaju.com.my/track-trace/',
'Origin: http://poslaju.com.my'
));
}
if ($usecookie) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
return $result;
}
function getStr($string,$start,$end){
$str = explode($start,$string,2);
$str = explode($end,$str[1],2);
return $str[0];
}
$url = 'http://poslaju.com.my/track-trace/';
$result_curl = _curl($url,'','','','','');
$x_user_key = getStr($result_curl,'{ "X-User-Key": "','" }');
$id_track = 'EP024922993MY';
$url = 'https://apis.pos.com.my/apigateway/as2corporate/api/v2trackntracewebapijson/v1/?id='.$id_track.'&Culture=En';
$result_curl = _curl($url,'','','','',$x_user_key);
echo $result_curl;
?>
Change id on your mind
You can get json content
Use print_r(json_decode($content_you_got)
And result you will have like this
