I have Laravel application and I want to use php artisan up
and php artisan down
commands from separated PHP script on the /public
folder like the following:
<?php
// /public/stop.php
if (!isset($_GET['state'])){
exec(('cd ../ ; php artisan down --message "Recovery and Updating. Please try again later."'));
header('Location:/');
}
else{
exec(('cd ../ ; php artisan up'));
header('Location:/');
}
The above script is accssible via: http://example.com/stop.php
Now I want to use $_SERVER['REMOTE_ADDR']
to check the client's IP address, to restrict access to this script from localhost i.e 127.0.0.1 like the following:
<?php
if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1'){
die('Error: It could not be executed.');
}
Regarding security concerns, about faking the IP from the client side. This question: How to fake $_SERVER['REMOTE_ADDR'] variable? confuses me, while this answer said it possible to make fake IP, that answer said it is not possible!
So, I need clear answer, could any someone able to trick Apache or PHP and make it get a fake IP?
Notice: My server is Apache server and PHP is 7.0.
Notice 2: This question is another approach than this How to get the client IP address in PHP? It is meant by faking the IP from the client not how to get the IP.