Home  >  Q&A  >  body text

PHP variables in CURL URL

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粉762730205P粉762730205260 days ago392

reply all(1)I'll reply

  • P粉771233336

    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;

    reply
    0
  • Cancelreply