Recently I created a script that accesses another script to run it. The only way the second script will run, is if it is accessed from the same server. To accomplish this I’ve made a simple if ($_SERVER['REMOTE_ADDR'] == "XXX.XXX.XXX.XXX") {
(Obviously the XXX.XXX.XXX.XXX is replaced with my server’s IP.)
However, I’d like the script to be more portable, so I want it to somehow detect the IP of the same server or something.
Suggestions? Or is this even possible?
To answer your question
$_SERVER['SERVER_ADDR']will return the IP Address of the server where the current script is executing, but yeah there’s better ways to do this, such as making the script unable to be accessed from the web in the first place.http://php.net/manual/en/reserved.variables.server.php