I tried this code in my local PHP server... everything works perfectly.. however when I uploaded this script to web hosting server, the authentication did not work. Somebody can explain why this script doesn't work on webserver?
"Authorization: Basic " . base64_encode("$username:$password")
Script:
$url = 'http://xxx.xxx.xxx.xxx:9080/apex/api/query?filtername=UNITSUMM&PARM_CONTAINER='.$contrNo.'&operatorId=BIG&complexId=KSA&facilityId=DMM&yardId=RRY';
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
));
$data = @file_get_contents($url, false, $context);
$convert = explode("
", $data);
It would be helpful if you could post whatever error message you're seeing, or you can find in the error logs.
It might be that your hosting provider doesn't allow outgoing connections to port 9080, or is blocking your connection based on some other criteria.
You might be able to debug your script if you print out the value of base64_encode("$username:$password") - perhaps one of these variables isn't getting set to the correct value.