Using wordpress through a proxy server

Where the web server hosting the WordPress site is located behind a proxy server, the WordPress admin and user may experience technical problems. Symptoms include:

– very slow loading of the dashboard
– askimet not working

These can be resolved by first setting proxy credentials in wp-includes/class-snoopy.php and then editing the akismet_http_post function in wp-content/plugins/askimet/askimet.php along the lines suggested at:

http://comox.textdrive.com/pipermail/wp-trac/2006-August/003435.html

Where your proxy server requires authentication you will need to provide this in askimet.php using the line:

$http_request .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode _
('username:password')."rn";

remembering to substitute in your actual username and password.

The new akismet_http_post function should therefore be:

function akismet_http_post($request, $host, $path, $port = 80) { _
 global $wp_version;

// $http_request  = "POST $path HTTP/1.0rn";
// $http_request .= "Host: $hostrn";
 $http_request  = "POST http://$host$path HTTP/1.0rn";
 $http_request .= "Host: http://$hostrn";

$http_request .= "Content-Type: application/x-www-form-urlencoded; _
charset=" . get_option('blog_charset') . "rn";
 $http_request .= "Content-Length: " . strlen($request) . "rn";
$http_request .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode_
 'username:password')."rn";

 $http_request .= "User-Agent: WordPress/$wp_version | Akismet/2.0rn";
 $http_request .= "rn";
 $http_request .= $request;

 $response = '';
// if( false != ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
 if( false !== ( $fs = @fsockopen('your_proxy_address', your_proxy_port, _
$errno, $errstr, 10) ) ) {

  fwrite($fs, $http_request);

  while ( !feof($fs) )
   $response .= fgets($fs, 1160); // One TCP-IP packet
  fclose($fs);
  $response = explode("rnrn", $response, 2);
 }
 return $response;
}

4 thoughts on “Using wordpress through a proxy server

  1. Hi Dr Alan,

    Thank you so much for this, I was able to hack the akismet code and get it to work behind our firewall (using our proxy) thank you so much!

    Cheers,
    Mandy

    Like

  2. Thanks for posting this code. I am running WordPress 3.0 and Akismet v2.2.9. I was curious if you may have a code update that would work with this? The server that hosts our site is not directly connected to the Internet.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s