0

I am new in computer science and also on this site. I am using php *5.4.** on localhost server and trying to get user ip address something like this

$ipaddress = $_SERVER['REMOTE_ADDR']; echo 'Your IP address (using $_SERVER[\'REMOTE_ADDR\']) is ' . $ipaddress . '<br />';

In output comes something like this:

Your IP address (using $_SERVER['REMOTE_ADDR']) is ::1

if possible give me please secure method to get ip address and prevent any type of attacks with ip address

Phoenix
  • 467
  • 1
  • 11
  • 23

1 Answers1

1

You are running the server on your computer so this is the only thing you're going to get. It does basically mean the same as 127.0.0.1.

If you do run it from a different computer in the network (or the internet), you'll be getting what you expect.

Andrius
  • 5,934
  • 20
  • 28
  • 1
    is `$_SERVER['REMOTE_ADDR']` secure ? – Phoenix Nov 06 '15 at 08:16
  • 1
    How do you defined 'secure'? The variable, will obviously show the proxy IP if the person is using a proxy. There are other variables that could help you get the real IP but that's almost never the case. You can read up on other variables mentioned [here](http://stackoverflow.com/a/15699240/1610183). But as far as you're concerned, `REMOTE_ADDR` should do just fine. – Andrius Nov 06 '15 at 08:21