0

We are executing a curl function using php. curl execution was working properly and getting the result, but we have to do the following step every morning:

We need to open the particular URL in browser first.

Is there anything we need to do in curl/php script to avoid the above step? Is this related a security issue or something?

below is my code:

$curl = curl_init(); 
curl_setopt($curl,CURLOPT_HTTPHEADER,array ("Content-Type:application/x-www-form-urlencoded"));
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, 'client_id=' . urlencode($client_id) . '&' .
    'client_secret=' . urlencode($client_secret) . '&' .
    'grant_type=client_credentials' . '&' .
    'scope=openid'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, FALSE);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $token_url);
$response = curl_exec($curl);
2
  • Try to make the cURL request perfectly mimic the browser request. The website doesn't know what you are using to access the page, only the headers that you send along with the request. I doubt you are using MSIE 5.01. Get the user agent string from a browser that works and use that and figure out if there are any other headers sent as well, (e.g. an accept header). Commented Jan 14, 2014 at 14:04
  • Also, how are you determining that you need to open the URL in a browser first? What errors are you getting? Commented Jan 14, 2014 at 14:09

1 Answer 1

2

Add this

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);  // you already have this  
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); 

CURLOPT_SSL_VERIFYHOST

1 to check the existence of a common name in the SSL peer certificate. 2 to check the existence of a common name and also verify that it matches the hostname provided. In production environments the value of this option should be kept at 2 (default value).

Source : https://www.php.net/curl_setopt

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ABhik its worked afte adding curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.