I've searched many previous posts here but nothing seems to solve my problem. In short, I want to include a PHP variable in the code below. The code below works fine because it is hardcoded, but when I replace the word MAYIAHH with the variable $hid
(declared), I get an error.
I've tried CURLOPT_POSTFIELDS
and various methods but nothing seems to help. Any ideas?
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; }
P粉7712333362024-02-26 11:19:25
Have you tried concatenating the url string?
$hid = 'MAYIAHH'; $url = 'https://rest.reserve-online.net/availability?properties='.$hid; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); 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;