Skip to content

Instantly share code, notes, and snippets.

@jamesmehorter
Last active August 25, 2016 16:51
Show Gist options
  • Save jamesmehorter/58a505949d1f395138f684ad7dbe7d9d to your computer and use it in GitHub Desktop.
Save jamesmehorter/58a505949d1f395138f684ad7dbe7d9d to your computer and use it in GitHub Desktop.
Only allow specific ips and ip ranges access to xmlrpc.php
<?php
$allow_access = false;
$visitor_ip = $_SERVER['REMOTE_ADDR'];
// Enter precise ips, or omit the last chunk to do a range
$allowed_ips = array(
'192.0.118.', // WPCOM Jetpack Range
'192.0.114.', // WPCOM Jetpack Range
'192.0.116.', // WPCOM Jetpack Range
'192.0.101.', // WPCOM Jetpack Range
'192.0.100.', // WPCOM Jetpack Range
'192.0.99.', // WPCOM Jetpack Range
);
// Look through the allowed ips/ranges and determine
// if this visitor should be allowed access
foreach( $allowed_ips as $allowed_ip ) {
// Is this exact visitor ip allowed access?
// OR, Is the visitor's ip range allowed access?
if ( $visitor_ip === $allowed_ip || false !== strpos( $visitor_ip, $allowed_ip ) ) {
$allow_access = true;
break;
}
}
if ( ! $allow_access ) {
header( 'HTTP/1.0 403 Forbidden' );
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment