Variables cannot contain periods. PHP will assume you are concatenating the vairable with a constant hence the undefined constants error. It has to either be joined with the variable or using an under score. It cannot contain hyphens as well.
If the var_dump( $responseData ) is NULL then try this:
if( isset( $responseData) ):
echo 'sorry, we have no $responseData ';
// do stuff or exit;
endif;
Edit:
From the Free PHP Online Manual
Return Values ¶
Returns the value encoded in json in appropriate PHP type. Values true, false and null are returned as TRUE, FALSE and NULL respectively. NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.
Yes. In PHP, it assumes that once you start putting in periods, it starts to assume you are concatenating the variable. So it will look for those concatenations. Since there are no dollar sign in front of success, it assumes you are referencing a constant. Thus the undefined constants error. To avoid this, you have to use a whole variable such as $responseDataSuccess.
Also, where is success coming from anyways? Are you trying to get the response of the json file? If so, this is already incorrect. json files are just like stdClass objects and as such, you must treat them like stdClass objects.
Sorry to keep updating, but am trying out a few options, i am this stage below and the echo I put in did show on the page, but below are a load of warnings I’m getting too.
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in \\contact.php on line 33
Warning: file_get_contents(): Failed to enable crypto in \\contact.php on line 33
Notice: Trying to get property of non-object in \\contact.php on line 37
I’m testing in a dev environment without the SSL certificate, but when I test it on the live server which has ssl it still doesnt work, so I think I have written that issue off
Then when I submitted after filling all the fields in, I got this below which looks fine to me.
name: uuykuykuyk
email: info@aceb.co.uk
company: jyytjtyj
phone: 07951178120
message: jytjtyjty
g-recaptcha-response: 03AJIzXZ6B(just part of a huge line of numbers and letters)
submit: Send message
So do you reckon I’m being blocked from connecting to google from my own server?
And when I var_dump $responseData I get usually something like string(6)
I haven’t tried it myself, it just seems logical that if the connection is refused (because the SSL isn’t working / configured) then the subsequent code that relies on stuff coming back from that call will also fail. $captcha_success->success is created when you decode the response, but you didn’t get a response, so it throws an error.
I’m surprised, though, that if the call to google is still failing with SSL issues, that it can suddenly find the success attribute to compare it to false. What's in $captcha_success` if you var_dump() it, does that give any clues, better error messages etc?
Just that, or is there anything in the string? Looking at the doc for the API call, it doesn’t look as if anything should return a 9-character string. Perhaps you could var_dump($verify) instead, see what the actual response is before you send it to json_decode().
It sort of does, but they use the old way that I was using $options, which caused all the ssl errors, somehow I need to work out where the info in $data such as secret and response goes to fit in with the $options bit, as the var_dump is saying Im missing the secret code and the response $POST