<bdo id='ABWGO'></bdo><ul id='ABWGO'></ul>
    1. <tfoot id='ABWGO'></tfoot>
      <i id='ABWGO'><tr id='ABWGO'><dt id='ABWGO'><q id='ABWGO'><span id='ABWGO'><b id='ABWGO'><form id='ABWGO'><ins id='ABWGO'></ins><ul id='ABWGO'></ul><sub id='ABWGO'></sub></form><legend id='ABWGO'></legend><bdo id='ABWGO'><pre id='ABWGO'><center id='ABWGO'></center></pre></bdo></b><th id='ABWGO'></th></span></q></dt></tr></i><div id='ABWGO'><tfoot id='ABWGO'></tfoot><dl id='ABWGO'><fieldset id='ABWGO'></fieldset></dl></div>

        <small id='ABWGO'></small><noframes id='ABWGO'>

        <legend id='ABWGO'><style id='ABWGO'><dir id='ABWGO'><q id='ABWGO'></q></dir></style></legend>

        如何在 PHP 中获取客户端 IP 地址

        时间:2024-08-10
      1. <i id='N9HPp'><tr id='N9HPp'><dt id='N9HPp'><q id='N9HPp'><span id='N9HPp'><b id='N9HPp'><form id='N9HPp'><ins id='N9HPp'></ins><ul id='N9HPp'></ul><sub id='N9HPp'></sub></form><legend id='N9HPp'></legend><bdo id='N9HPp'><pre id='N9HPp'><center id='N9HPp'></center></pre></bdo></b><th id='N9HPp'></th></span></q></dt></tr></i><div id='N9HPp'><tfoot id='N9HPp'></tfoot><dl id='N9HPp'><fieldset id='N9HPp'></fieldset></dl></div>

          <bdo id='N9HPp'></bdo><ul id='N9HPp'></ul>
          <tfoot id='N9HPp'></tfoot>
        • <small id='N9HPp'></small><noframes id='N9HPp'>

              <legend id='N9HPp'><style id='N9HPp'><dir id='N9HPp'><q id='N9HPp'></q></dir></style></legend>

                    <tbody id='N9HPp'></tbody>
                  本文介绍了如何在 PHP 中获取客户端 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何使用 PHP 获取客户端 IP 地址?

                  How can I get the client IP address using PHP?

                  我想记录通过他/她的 IP 地址登录我网站的用户.

                  I want to keep record of the user who logged into my website through his/her IP address.

                  推荐答案

                  无论你做什么,请确保不要信任从客户端发送的数据.$_SERVER['REMOTE_ADDR'] 包含连接方的真实 IP 地址.这是您能找到的最可靠的值.

                  Whatever you do, make sure not to trust data sent from the client. $_SERVER['REMOTE_ADDR'] contains the real IP address of the connecting party. That is the most reliable value you can find.

                  但是,它们可能位于代理服务器之后,在这种情况下,代理可能设置了 $_SERVER['HTTP_X_FORWARDED_FOR'],但该值很容易被欺骗.例如,它可以由没有代理的人设置,或者 IP 可以是来自代理后面的 LAN 的内部 IP.

                  However, they can be behind a proxy server in which case the proxy may have set the $_SERVER['HTTP_X_FORWARDED_FOR'], but this value is easily spoofed. For example, it can be set by someone without a proxy, or the IP can be an internal IP from the LAN behind the proxy.

                  这意味着如果您要保存 $_SERVER['HTTP_X_FORWARDED_FOR'],请确保保存 $_SERVER['REMOTE_ADDR'] 值.例如.通过将这两个值保存在数据库的不同字段中.

                  This means that if you are going to save the $_SERVER['HTTP_X_FORWARDED_FOR'], make sure you also save the $_SERVER['REMOTE_ADDR'] value. E.g. by saving both values in different fields in your database.

                  如果您要将 IP 作为字符串保存到数据库中,请确保您有至少 45 个字符的空间.IPv6 将继续存在,并且这些地址比旧的 IPv4 地址更大.

                  If you are going to save the IP to a database as a string, make sure you have space for at least 45 characters. IPv6 is here to stay and those addresses are larger than the older IPv4 addresses.

                  (请注意,IPv6 通常最多使用 39 个字符,但也有一个特殊的 IPv6 表示法对于 IPv4 地址,其完整形式最多可包含 45 个字符.因此,如果您知道自己在做什么,则可以使用 39 个字符,但如果您只想设置并忘记它,请使用 45).

                  (Note that IPv6 usually uses 39 characters at most but there is also a special IPv6 notation for IPv4 addresses which in its full form can be up to 45 characters. So if you know what you are doing you can use 39 characters, but if you just want to set and forget it, use 45).

                  这篇关于如何在 PHP 中获取客户端 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:排序依赖于另一个数组键值的数组 下一篇:使用 Apache 时在 PHP 中设置用于访问的环境变量

                  相关文章

                  <i id='BiKug'><tr id='BiKug'><dt id='BiKug'><q id='BiKug'><span id='BiKug'><b id='BiKug'><form id='BiKug'><ins id='BiKug'></ins><ul id='BiKug'></ul><sub id='BiKug'></sub></form><legend id='BiKug'></legend><bdo id='BiKug'><pre id='BiKug'><center id='BiKug'></center></pre></bdo></b><th id='BiKug'></th></span></q></dt></tr></i><div id='BiKug'><tfoot id='BiKug'></tfoot><dl id='BiKug'><fieldset id='BiKug'></fieldset></dl></div>
                  <tfoot id='BiKug'></tfoot>
                    <bdo id='BiKug'></bdo><ul id='BiKug'></ul>
                1. <legend id='BiKug'><style id='BiKug'><dir id='BiKug'><q id='BiKug'></q></dir></style></legend>

                    1. <small id='BiKug'></small><noframes id='BiKug'>