CodeIgniter Forums
Need help about IP Addresses - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Need help about IP Addresses (/thread-74839.html)



Need help about IP Addresses - SaraBailey - 11-14-2019

Hi!

I want to know the real IP address of the client accessing my app.  Why?
So I can compare it with my IP address.
I'm working on a web based desk top app and I do not want an employees logging in from anywhere other than physically in my office; unless an admin.

None of these below returns anything useful from behind LOCALHOST, it returns my own IP address as ::1 
Will I get a better result on a public host?  Is there a PHP.ini setting that I need to make?
Perhaps you have a better approach....


PHP Code:
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
   //ip from share internet
    $ip $_SERVER['HTTP_CLIENT_IP'];
}
elseif(!empty(
$_SERVER['HTTP_X_FORWARDED_FOR'])){
   //ip pass from proxy
    $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else{
    $ip $_SERVER['REMOTE_ADDR'];


Thank for help


RE: Need help about IP Addresses - muuucho - 11-14-2019

You should be able to get correct IPs from a live server.


RE: Need help about IP Addresses - dave friend - 11-14-2019

Is the server a shared hosting setup or something else? If you've got full control of the server then the easiest thing to do would probably be to use a firewall that only allows traffic from your office network.

(11-14-2019, 01:07 AM)SaraBailey Wrote: Will I get a better result on a public host? 

Yes and maybe. You might not always get the "real" ip as there could be a proxy server in the chain. But you should be able to tell if what you're getting is in the range of IP addresses used by your office network.