CodeIgniter Forums
Questions About IP Addresses - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Questions About IP Addresses (/showthread.php?tid=70677)



Questions About IP Addresses - CobolGuy - 05-13-2018

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'];

Thanks for any insights.


RE: Questions About IP Addresses - skunkbad - 05-13-2018

This might be best handled at the hardware firewall level of your network. Instead of doing something in your app to look for IP addresses, your firewall could just drop all inbound requests for the matching port, domain, etc.


RE: Questions About IP Addresses - Krycek - 05-13-2018

(05-13-2018, 08:13 PM)skunkbad Wrote: This might be best handled at the hardware firewall level of your network. Instead of doing something in your app to look for IP addresses, your firewall could just drop all inbound requests for the matching port, domain, etc.

This would be indeed the best way, only make the app available in your intranet.


RE: Questions About IP Addresses - InsiteFX - 05-14-2018

There are a lot of problems with doing it like that.

Like the user maybe behind a proxy etc;