File_get_contents error

I am using Google reCaptcha ver 3.0 and since last few days I am getting this error all of a sudden with the ‘file_get_contents’ function.

Below is the snippet of the code:


$url = ‘’;
$response = file_get_contents($url, false, stream_context_create($arrContextOptions));
$returnValue = json_decode($response);

Error returned:
“failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found”

If I take the url and execute it separately, it is returning the json value without any error.

Any ideas?

Since your URL includes special character &, file_get_contents() isn’t opening the URL. Please use urlencode() before passing the URL and check if it works. Do tell us if the problem persists.

1 Like

I tried that. My concern is that, it is working everyday until few days ago without any change in code. So I was wondering why it is giving error all of sudden and what changed.

Did it work?

I can’t really answer that. I think it is probably one of the biggest mysteries of programming.

No, it did not work…but thanks anyway.

Could you please tell me why are you sending “mysitekey” in the response section, and what is the mysecretkey and mysitekey?

I think this is the right way to send data:

$url = "";
$response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);

Where $_POST['g-recaptcha-response'] comes as the form data. Please try modifying the code.


Yes, I was already using $_POST['g-recaptcha-response'] in place of ‘mysitekey’. Sorry, I must have typed like that in the question above.

Like I said, it was working fine earlier and all of a sudden started giving error.

Based on my understanding, it looks like the page could not be found as mentioned in the url. But, when I took and executed the url in separate browser tab, it was giving me the response correctly.

I am sorry dear, but I think I won’t be able to help you anymore. I don’t see any errors in your code, and even the variations don’t work.

Please give me your site’s URL so that I can see the error page. Thank you.

I will leave this StackOverflow link where the person answering the question uses CURL. Please use that code.


Ok thank you. Will try that.

Tried that code in the article you have sent, but it is not working either. Looks like the the PHP version upgrade may have been causing the issue. Not sure. My smtp mail is also not working after that upgrade.

file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Further debugging and researching lead me to here. Apparently, the ssl certificate verification is failing and not sure why. Because I have ssl enabled from CloudFlare and it shows that my web site is secured.


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.