Digital Marketing

Could not open socket reCAPTCHA error

After months of receiving spam via my contact forms, I decided it was time to add reCAPTCHA to them in hopes of stemming the tide of junk. This is now under the control of Google. I thought there would be no problem with this. Having installed reCAPTCHA on my work websites, I knew what to do and everything worked fine on those sites. On Friday I made 3 forms on my own sites and everything worked as expected, on Saturday I made the last form I had but that one didn’t work. All I got was a “could not open socket” error.

Initially I thought that I must have made some mistake in the code, but after checking the code with what I had done the day before, I couldn’t see any errors. And more about the 3 forms I made the day before that worked, now they don’t work anymore and show the same error message, what the hell? Most frustrating was the fact that this was all the message said and gave no clue as to what was causing it. I made several attempts to find which section of the code was at fault by adding echoes throughout the php code, but none of them came up, just that damn error message. I thought there must be some problem with the server.

Someone must have had this problem before, so I turned my attention to Google for an answer. When I started typing ‘socket could not be opened’, the autocomplete showed me ‘socket recaptcha could not be opened’, ah ha! But I couldn’t think why it might have worked yesterday and not today. After reading a lot of useless posts, I found this: code.google.com/p/recaptcha/issues/detail?id=26 which, while it didn’t have the exact answer, helped me figure out the answers to my own problems.

After reading this thread I came to the conclusion that my problem was twofold and explained why it had worked yesterday and not today. The main problem was my web host, in their attempt to help they introduced (a long time ago) blocking outgoing connections to remote IP addresses from my sites. This is one to keep in mind if you are auto blogging using wp-o-matic, any feeds you add will most likely be blocked by this until you add the IP to the allowed list from your dashboard.

I suppose there is a good reason for them to do this, but I can imagine that it has given the inexperienced nightmares. It had obviously worked yesterday because it was new, once the server knew the connection was being made it blocked it. It was probably the amount of testing I did that made the connection noticeable and possibly it was a good job that it became noticeable so quickly or that I haven’t noticed for some time.

So which IP should I add to the allowed list? The line of code in recaptchalib.php identified as the problem in the previous thread was:

define(“RECAPTCHA_VERIFY_SERVER”, google.com);

So what I needed was the IP of google.com. mxtoolbox.com/SuperTool.aspx is a very useful tool that I have been using for a long time. A DNS lookup for google.com gave me 5 options for an IP, 74.125.227.48 to 74.125.227.52, so now I have:

define(“RECAPTCHA_VERIFY_SERVER”, “74.125.227.48”);

Adding this IP to the list of allowed remote IPs from my control panel fixed the problem on all my forms. Score!

Leave a Reply

Your email address will not be published. Required fields are marked *