1

I have an URL like this one. I'm trying to get location from header, but its not showing location as normal. Here is my function to get header info.

function headerInfo ($service_url) {
    $handle = curl_init($service_url);
    curl_setopt_array($handle, array(
        CURLOPT_RETURNTRANSFER => 1, 
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_NOBODY => 0, 
        CURLOPT_HEADER => 1
    ));
    $curl_response = curl_exec($handle);
    return $curl_response;
}

Response from PHP:

php header response

Response when trying from browser (chrome developer tool result): chrome header response

1
  • Might simply be invalid parameters or an unknown hash, or PHP/Curl requests being blocked. Have you contacted the service provider?
    – mario
    Dec 9, 2018 at 9:42

1 Answer 1

1

Try setting a valid User-Agent.

Like so:

function headerInfo ($service_url) {
    $handle = curl_init($service_url);
    curl_setopt_array($handle, array(
        CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
        CURLOPT_RETURNTRANSFER => 1, 
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_NOBODY => 0, 
        CURLOPT_HEADER => 1
    ));
    $curl_response = curl_exec($handle);
    return $curl_response;
}

You can find a list of valid User-Agents here:

Valid User-Agents

4
  • I've tried that before, but nothing changes then I was removed it from curl function.
    – Simon
    Dec 9, 2018 at 9:57
  • You might try setting the NOBODY to 1.
    – Joseph_J
    Dec 9, 2018 at 10:01
  • Thanks for your answers. Might be the server was blocked cURL request, kinda weird.
    – Simon
    Dec 9, 2018 at 10:17
  • Hey no problem, I hope you get it figured out. Curl can finicky sometimes. Good luck.. ~Cheers
    – Joseph_J
    Dec 10, 2018 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.