Answer the question
In order to leave comments, you need to log in
Why does the $_SERVER["REMOTE_ADDR"] include show the server ip?
In the include, it $_SERVER["REMOTE_ADDR"]
displays the ip of the server, I sin on htaccess, since I set up dynamic subdomains. From a subdomain I come - such a bug. Directly everything is fine.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.test\.ru$
RewriteCond %{REQUEST_URI} ^/show/(.*)
RewriteRule ^(.*)$ http://test.ru/show.php?id=%1 [L,P]
Answer the question
In order to leave comments, you need to log in
Decided so. Crutch, but still works.
function get_client_ip() {
$ipaddress = '';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ipaddress = $_SERVER['REMOTE_ADDR'];
}
return $ipaddress;
}
PHP script published via apache2+ nginx ?
If yes, then PHP gets the nginx host address. You can set up IP address translation through the apache module 'mod_remoteip'.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question