是否可以使用 PHP 或 Apache 从客户端获取网络域? [英] Is it possible to get Network Domain from Client with PHP or Apache?

查看:21
本文介绍了是否可以使用 PHP 或 Apache 从客户端获取网络域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种解决方案,用于识别专用网络中的客户端网络域或工作组.基于它,我必须更改一些访问权限.

I'm working on a solution to identify client Network Domain or Workgroup in a private network. Based on it, I must change some access permissions.

我不能通过 IP 地址做到这一点,因为它是不可信的,只有网络域/工作组.

I can't do that through IP address because it isn't trustable, only network domain/ workgroup.

由于我不知道的原因,我无法使用登录屏幕,访问必须是自动且无缝的.

For reasons unknown to me I can't have a login screen, access must be automatic and seamless.

有人知道我该怎么做吗?

Someone know how can I do it?

推荐答案

可以使用 gethostbyaddr 函数 http://php.net/manual/en/function.gethostbyaddr.php:

    $proxy = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : false;

if(!!$proxy){
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
     echo "Warning: Your cliend is using proxy, may could not determine hostname";
    }else{
    $ipaddress = $_SERVER['REMOTE_ADDR']; //
    }
    $hostname = gethostbyaddr($ipaddress); //Its will return domain + machine-name inside a private network.

    if($ipaddress  == $hostname){
     echo "Impossible to determine hostname for: ", $ipaddress ;
    }else{
      echo "The hostname for ", $ipaddress, "is : ",  $hostname;
    }

但是使用应用程序/会话层到网络层的通信有点复杂.您一定不要相信它会在 php 应用程序中进行访问控制.

But the communication using application / session layer to network layer is a little complicated. You must don't trust it to access control in php applications.

要获取所有公共 IP 地址,可以使用 WebRTC (javascript) 代替远程地址http 标头.

To get all public IP Address is possible to use WebRTC (javascript) instead remote addrees from http header.

这篇关于是否可以使用 PHP 或 Apache 从客户端获取网络域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆