dpwdldgn43486 2016-02-26 13:10
浏览 68
已采纳

Javascript / PHP - 查找客户端是否在同一网络中

I have an website hosted on local server in my LAN network. This server is exposed outside by port forwarding from router. I want to know if a client connects from outside the LAN or inside the LAN

  • 写回答

1条回答 默认 最新

  • douke6027 2016-02-26 13:31
    关注

    Any request to your server that has been port forwarded will appear to originate from the IP address of the device that performed the port forwarding.

    So you just need to test:

    if ($_SERVER['REMOTE_ADDR'] == $the_ip_address_of_the_router_on_the_lan)
    

    where $the_ip_address_of_the_router_on_the_lan is a known value such as 192.168.0.1.

    Devices on the LAN, assuming they access your server directly, will make requests that appear to originate from their own LAN IP address.

    Warning: If the server is accessed using a hostname (such as foo.example.com), and you use the same hostname both inside and outside the LAN, and the DNS inside the LAN points that hostname to the Internet facing ip address of the router, then the requests will still be port forwarded by the router.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统