Software Developer

Print or var_dump To Screen, But Only On My IP Address

This lets you print PHP variable information, or any debugging code, to the screen, but only on your IP address. This is useful when you have to test on a live site, and for whatever reason you want to print to the screen rather than to error logs, but you don’t want visitors to see your var_dump or print_r.

This also works in WordPress. You can use it in a WordPress template file, or in a function which is used to output stuff to the screen (i.e. a function hooked to a template file hook).

You have to change the ‘99.99.99.999’, below, to your own current IP address. You can get your current public IP address, quickly, by searching “What’s my IP address” in your favorite search engine.

Replace the variable $stuff_to_print with whatever variable you want to print to your screen. You can change line 10 to whatever it is you need to print to the screen, such as:

<?php var_dump( $data ); ?>

Note: I add the pre tags on line 10 in order have arrays printed in a reader-friendly format instead of a continuous, hard-to-read, output.

/************************************************************
*
* Print stuff to the screen, but only on my IP Address
*
************************************************************/
if ( $_SERVER['REMOTE_ADDR'] == '99.99.99.999') {

	?>

	<pre><?php echo print_r( $stuff_to_print, true ); ?></pre>

	<?php
}

By

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]