0

I literally have similar cURL scripts running on other areas of this PHP page, and they work just fine. But for some reason, this one is different enough to be causing me problems. No error message, it just doesn't seem to be hitting the endpoint for some reason. Can you see any reason why this wouldn't work?

ob_start();
$destination = "https://www.example.com/record_serial_number.php?serial_number=" . $serial_number . "&employee_name=" . $employee_name . "&scan_purpose=Barcode printed&value=";
$destination = urlencode($destination);

$url = $destination;  
$ch = curl_init();  

// set URL and other appropriate options  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

curl_setopt($ch, CURLOPT_USERPWD, "hidden_username:hidden_password");
$response = curl_exec($ch);
curl_close($ch);

$response .= ob_get_contents();
ob_end_clean();
  • Have you checked [`curl_error()`](https://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php) – Nigel Ren Jun 28 '21 at 18:32
  • 1
    Well, you've completely messed up your URL with urlencode. `https%3A%2F%2Fwww.example.com%2Frecord_serial_number.php%3F`... you need to use urlencode on your individual variables, not the whole string. – aynber Jun 28 '21 at 18:34

1 Answers1

0

You need to use curl_errno() and curl_error() to find out if curl_exec() encountered an error.

Tom
  • 880
  • 6
  • 17