2

WordPress テーマで BWP Recaptcha (Better WordPress Recaptcha) を使用しています。私のシステムはプロキシの背後にあります....

しかし、投稿しようとするたびにエラーが発生します

Could not open socket

だから私は解決策をグーグルで検索し、関数を変更する必要があるものを手に入れました

recpatchalib.php

変化する

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.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";

    if (!empty($proxy_username)) {
        $auth_string = base64_encode($proxy_username . ($proxy_password != '' ? ":{$proxy_password}" : ''));
        $http_request .= "Connection: close\r\n";
        if ( !empty($auth_string ) ) $http_request .= "Proxy-Authorization: Basic {$auth_string}\r\n";
    }

    $http_request .= "\r\n";
    $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("\r\n\r\n", $response, 2);

    return $response;
}

そして、このソリューションを実装した後でも、システムはまだ言う

Could not Open socket

私はベテランの PHP プログラマーではありません... wordpress を試してみました。

この点に関するヘルプは役に立ちます

4

3 に答える 3

0

私はこのように関数を編集し、私のために働きました:

function _recaptcha_http_post($host, $path, $data, $port = 80) {

    $proxy_host = 'my.private.proxy';
    $proxy_port = 3128;
    $proxy_user = 'user';
    $proxy_pass = 'pass';

    $req = _recaptcha_qsencode ($data);

    $http_request  = "GET http://$host$path?$req HTTP/1.0\r\n";
    $http_request .= "Proxy-Authorization: Basic ".base64_encode($proxy_user.":".$proxy_pass)."\r\n";
    $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
    $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
    $http_request .= "\r\n";

    $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("\r\n\r\n", $response, 2);

    return $response;
}
于 2013-12-23T22:56:06.680 に答える
0

WordPress 2.8 の時点で、新しいプロキシ サポートが組み込まれ、wp-config.php 定義によって制御されます。recaptchalib.php を変更して、私にとってはうまくいくように思われる次のものを含めました (そして、プロキシを 1 か所で定義するだけで済みます)。

function _recaptcha_http_post($host, $path, $data, $port = 80) {

    $req = _recaptcha_qsencode ($data);

    $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";

    $proxy = new WP_HTTP_Proxy();

    $url = "http://" . $host . ( $port == 80 ? "" : ":" . $port) . $path;

    if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
        $http_request = "POST " . $url . " HTTP/1.0\r\n" . $http_request;
        $sockhost = $proxy->host();
        $sockport = $proxy->port();

        if ( $proxy->use_authentication() ) {
            $http_request .= "Connection: close\r\n";
            $http_request .= $proxy->authentication_header() . "\r\n";
        }
    } else {
        $http_request = "POST $path HTTP/1.0\r\n" . $http_request;
        $sockhost = $host;
        $sockport = $port;
    }

    $http_request .= "\r\n";
    $http_request .= $req;

    $response = '';
    if( false == ( $fs = @fsockopen($sockhost, $sockport, $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;

}

于 2014-07-08T13:24:30.750 に答える