M
M
maiskiykot2018-05-20 16:31:31
PHP
maiskiykot, 2018-05-20 16:31:31

How to detect script call from localhost?

With this 5.6, it's like learning to code again. It was necessary to make a check that the script is called from localhost, so that debugging information is hidden when uploaded to the server. Went through the entire $_SERVER and none of the conditions work. What is the easiest way to determine the locale? I understand that you can first call $_SERVER['DOCUMENT_ROOT'] and then write it manually, but I want something simpler. Thanks in advance for the tip.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maiskiykot, 2018-05-20
@maiskiykot

$_SERVER['HTTP_X_REAL_IP'] helped! The question remains: why?

A
Alexander Aksentiev, 2018-05-20
@Sanasol

Well, usually this is done by setting env=production or development
And you can determine the locale by the IP address of the user entering $_SERVER['REMOTE_ADDR'], if it is 127... or 192.168.... then most likely it is a local server (there is still an option that the web server is configured crookedly).
So, rather, the first method with manual indication in the locale config is it or not.
The server itself is not aware that it is local or not, there is no such concept in it at all. It is quite always running in LAN, and may (should) be inaccessible from outside. Only through apache/nginx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question