 <p>This will do the trick:</p> <pre><code>if($_SERVER['REMOTE_ADDR'] === '127.0.0.1') { // do something } </code></pre> <p>Be careful you don't rely on X_FORWARDED_FOR as this header can be easily (and accidentally) spoofed.</p> <p>The correct way to do this would be to set an environmental variable in your server configuration and then check that. This will also allow you to toggle states between a local environment, staging and production.</p>