0

Is any method is available which through we can determine that our current connection is through internet Or intranet using php script.

Thanks.....

2 Answers2

1

You can use $_SERVER["HTTP_HOST"] variable to obtain if it is localhost or other IP address.

hsz
  • 148,279
  • 62
  • 259
  • 315
  • This elaborates on this solution somewhat. http://stackoverflow.com/questions/13818064/check-if-an-ip-address-is-private – Anthony Sterling Aug 28 '13 at 07:35
  • Intranet generally means "from the same LAN as the server", not just "from the same computer as the server" – Quentin Aug 28 '13 at 07:50
1

You could check $_SERVER['SERVER_ADDR'] against $_SERVER['REMOTE_ADDR'] If the first number of the IP is the same and is 192,172,10 or 127 then it is most likely an intranet page.

like this:

function is_intranet() {
  $serverIP = explode('.',$_SERVER['SERVER_ADDR']);
  $localIP  = explode('.',$_SERVER['REMOTE_ADDR']);
  return ( 
    ($serverIP[0] == $localIP[0]) && 
    (in_array($serverIP[0],array('127','10','172','192') ) ) 
  );
}

this can be improved upon a bit using the rules here: http://en.wikipedia.org/wiki/Private_network