php check if localhost

Output debug info only on localhost with IP='127.0.0.1':


if( in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) ) ) { // debug mode on localhost ('127.0.0.1' IP in IPv4 and IPv6 formats)

	// in_array( $_SERVER['HTTP_HOST'], array( 'localhost', '127.0.0.1' ) ) // alternative

	echo '<pre_>'; // add indentation formatting

	print_r( $output ); // debug mode on localhost

	echo '</pre_>'; // remove underscore

}

1 thought on “php check if localhost”

Leave a Comment