This is not secure ^^ any would be attacker can just set that header to whatever they like. In general the whole idea isn't something I'd recommend.
That said I imagine the intention is that the code gets put into your themes function.php something like the below
add_action( 'init', 'checkip' );
function checkip() {
##code goes here
}
For the code to process multiple IPs
$ip = array("127.0.0.1","192,168.0.1");
if ( ( is_single() || is_front_page() || is_page() ) && !is_page('login') && !is_user_logged_in()){
if ( in_array($_SERVER['REMOTE_ADDR'], $ip) || in_array($_SERVER['HTTP_X_FORWARDED_FOR'], $ip) ) {
return;
} else {
auth_redirect();
}
}