How to prevent a function from running based on host (ie web vs local)?

$whitelist = array('127.0.0.1');

if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
// not valid
}

For more info on how it works.
https://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php