News:

Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

curl alternative to fsockopen for reCAPTCHA

Started by lsucycling, December 16, 2007, 08:59:53 PM

Previous topic - Next topic

lsucycling

Hi, I'm trying to put a reCAPTCHA challenge onto my user form (it was getting spammed....). Unfortunately, the reCAPTCHA example codes require fsockopen, which I'm reading was disabled on freepgs.

Does anyone know of an alternative to fsockopen?, possibly curl? (and how to implement it?) Its getting beyond me at the moment  ???
Heres the function that needs to talk to the reCAPTCHA server (including comments):

/**
* 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) {

        $req = _recaptcha_qsencode ($data);

        $http_request  = "POST $path HTTP/1.0\r\n";
        $http_request .= "Host: $host\r\n";
        $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
        $http_request .= "Content-Length: " . strlen($req) . "\r\n";
        $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
        $http_request .= "\r\n";
        $http_request .= $req;

        $response = '';
        if( false == ( $fs = @fsockopen($host, $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("\r\n\r\n", $response, 2);

        return $response;
}

Any help much appreciated!

ps. Is there a list anywhere of what codes/functions are enabled/disabled on freepgs?

Ben

I don't know of a way via curl (Honestly, I've never used curl, so I'm no help there), but on your other question:

You can find out what functions are disabled via a phpinfo() call.

The current functions disabled list is as follows:

Quoteshell_exec,exec,passthru,system,dl,proc_open,proc_close,proc_nice,proc_terminate,proc_get_status,popen,pclose,dlopen,pfsockopen,fsockopen
--Ben
Ben@freepgs.com