Reputation: 33090
Should we check $_SERVER['REMOTE_SERVER']
or what?
Upvotes: 2
Views: 1160
Reputation: 6124
This code will help you.
<?php
if($_SERVER['SERVER_NAME'] == 'localhost')
{
echo 'localhost';
}
?>
Upvotes: 1
Reputation: 6354
This will do the trick:
if($_SERVER['REMOTE_ADDR'] === '127.0.0.1') {
// do something
}
Be careful you don't rely on X_FORWARDED_FOR as this header can be easily (and accidentally) spoofed.
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.
Upvotes: 4
Reputation: 6000
Check
$_SERVER['REMOTE_ADDR']=='127.0.0.1'
This will only be true if running locally. Be aware that this means local to the server as well. So if you have any scripts running on the server which make requests to your PHP pages, they will satisfy this condition too.
refered from : How to check if the php script is running on a local server?
Upvotes: 0