Reputation: 607
This is not working, it doesn't throw me any errors too
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
//My code
}
//NOTE: echo $_SERVER['REMOTE_ADDR'] is "::1"
Upvotes: 0
Views: 627
Reputation: 509
because you're in local host:
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') {
//Your code
}
Upvotes: 0
Reputation: 2600
if($_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
//Your Code
}
this should make it safe even if you migrate to another server.
as stated before, server is configured to handle it with ipv6 address and ::1 is the ipv6 equivalent of 127.0.0.1
Upvotes: 1
Reputation: 2178
The reason you got ::1 is that you are using ipv6. Turn it off or have both 127.0.0.1 and ::1 in your statement.
Upvotes: 1
Reputation: 157364
Everything looks fine in your code, Try this and see, if it's IPv6, this should work
if($_SERVER['REMOTE_ADDR'] == '::1') {
//Your Code
}
Upvotes: 2