PHP: function is_me()

ript>

A very useful function to determine first if the visitor is the developer or not and then act accordingly.

Code:

/* check if client is me */
function is_me()
{
$ip=$_SERVER["REMOTE_ADDR"];
$br=$_SERVER["HTTP_USER_AGENT"];
if (($ip=="127.0.0.1") and (strstr( $br, "Firefox")))
return true;
return false;
}

Explanation:
If the visitor’s IP is 127.0.0.1 (=localhost) and the browser is “Firefox” then the visitor is me!

Usage example:

if (is_me()) { error_reporting( E_ALL); } else { error_reporting( 0); }

With the above snippet, one developer can check for errors and warnings in a running system without the casual visitor noticing a thing. It is very easy also to view the web-page with another browser to check what the visitor actually sees.


Visit The Light of the LAMP blog for more…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.