post icon

PHP Code to check if its running on ‘localhost’ or not

sometime we have to run two different code’s, one on local machine another set of code on live server.

So to check it

<?php
$url=”http://”.$_SERVER[‘HTTP_HOST’];
if($url == “http://localhost”)
{
//code to be run on local machine
}
else
{
// code to run on server machine
}
?>

April 8, 2013

Comments are closed.

Leave a comment