mbirth
unread,Sep 8, 2009, 4:33:25 AM9/8/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to reCAPTCHA
I had to use cURL because we use a HTTP proxy for outbound connections
and fsockopen() tried to connect directly. This seems to work:
/**
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
function _recaptcha_http_post($host, $path, $data, $port = 80) {
$add_headers = array(
"Host: $host",
);
$curl = curl_init( 'http://' . $host . ':' . $port . $path );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_1_0 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'reCAPTCHA/PHP' );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
curl_setopt( $curl, CURLOPT_HEADER, true );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $add_headers );
if ( isset( $_ENV['http_proxy'] ) && !empty ( $_ENV
['http_proxy'] ) ) {
curl_setopt( $curl, CURLOPT_HTTPPROXYTUNNEL, true );
curl_setopt( $curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP );
curl_setopt( $curl, CURLOPT_PROXY, $_ENV
['http_proxy'] ); // CURLOPT_PROXYUSERPWD as username:password
needed?
}
$response = curl_exec( $curl );
if ( $response === false ) die('Error connecting to ' .
$host . '.');
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
Cheers,
-mARKUS