I am using BWP Recaptcha (Better WordPress Recaptcha) in my WordPress theme. My System is behind a proxy….
But every time i try to post it gives an error
Could not open socket
So i googled the solution and got a something where i have to change a function in
recpatchalib.php
Change
function _recaptcha_http_post($host, $path, $data, $port = 80) {
$proxy_host = 'PROXY-HOST';
$proxy_port=PROXY-PORT;
$proxy_username='PROXY-USERNAME';
$proxy_password='PROXY-PASSWORD';
$req = _recaptcha_qsencode ($data);
$http_request = "POST http://$host$path HTTP/1.0rn";
$http_request .= "Host: $hostrn";
$http_request .= "Content-Type: application/x-www-form-urlencoded;rn";
$http_request .= "Content-Length: " . strlen($req) . "rn";
$http_request .= "User-Agent: reCAPTCHA/PHPrn";
if (!empty($proxy_username)) {
$auth_string = base64_encode($proxy_username . ($proxy_password != '' ? ":{$proxy_password}" : ''));
$http_request .= "Connection: closern";
if ( !empty($auth_string ) ) $http_request .= "Proxy-Authorization: Basic {$auth_string}rn";
}
$http_request .= "rn";
$http_request .= $req;
$response = '';
if( false == ( $fs = @fsockopen($proxy_host, $proxy_port, $errno, $errstr, 10) ) ) {
die ('Could not open socket');
}
fwrite($fs, $http_request);
while ( !feof($fs) )
$response .= fgets($fs, 1160); // One TCP-IP packet
fclose($fs);
$response = explode("rnrn", $response, 2);
return $response;
}
And even after implementing this solution the system still says
Could not Open socket
I am not a seasoned PHP programmer… i was jsut trying my hands on wordpress
Any help in this regard would be helpful
You may need to check if you have enabled “allow_url_fopen”. If it is not enabled you will not be able to open sockets or do remote calls like reCaptcha requires.
Try looking at your php.ini file in the blog’s root directory (mine is actually in /etc since I run my own server) and check for “allow_url_fopen=On”. If it is not there then add it.
I edited the function like this and worked for me:
As of WordPress 2.8, there’s new proxy support built in and controlled by wp-config.php definitions. I’ve modified the recaptchalib.php to include the following which seems to work for me (and I only have to define the proxy stuff in one place).
}