Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which to use: REMOTE_ADDR or SERVER_ADDR

Tags:

php

Any real difference between

$_SERVER['REMOTE_ADDR']
$_SERVER['SERVER_ADDR']

I'm tracking visitors to a page, and I've always used REMOTE_ADDR, but recently I saw a script that collected both information. Is this a better practice or not needed?

like image 205
syhuro Avatar asked Aug 03 '10 07:08

syhuro


People also ask

Is Remote_addr secure?

Yes, it's safe. It is the source IP of the TCP connection and can't be substituted by changing an HTTP header.

What is _server Remote_addr?

$_SERVER['REMOTE_ADDR'] gives the IP address from which the request was sent to the web server.


2 Answers

The $_SERVER['REMOTE_ADDR'] returns the IP address from which the user is viewing the current page. And $_SERVER['SERVER_ADDR'] returns the IP address of the server under which the current script is executing.

So what should you use:

You should use $_SERVER['REMOTE_ADDR'].

More Info:

  • http://php.net/manual/en/reserved.variables.server.php
like image 54
Sarfraz Avatar answered Sep 29 '22 16:09

Sarfraz


SERVER_ADDR is the address of the server PHP code is run on. You don't need to collect it. REMOTE_ADDR is the one you want.

like image 29
jmz Avatar answered Sep 29 '22 14:09

jmz