I have searched many previous posts here, and nothing seems to work with my issue. In a nutshell, I am looking to include a PHP variable in the following code. This code below works as it is hardcoded, but I get an error when I replace the word MAYIAHH with a variable $hid
(which has been declared).
I have tried CURLOPT_POSTFIELDS
and all sorts, but nothing seems to help. Any ideas, please?
function send_request($xml)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
'https://rest.reserve-online.net/availability?properties=MAYIAHH');
curl_setopt($ch, CURLOPT_USERPWD, "uname:pass");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
My Answer:
$username . ':' . $password);_
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$hid = "MAYIAHH";
$xml = "
$response = send_request($xml, $hid);
echo $response;
Rate this post
5 of 5 based on 3237 votesComments