回覆列表
  • 1 # tkosh25997

    因為涉及相容性問題,可以透過req.header("x-forwarded-for")與req.connection.remoteAddress來獲取IP地址,下面是封裝好的一個函式:

  • 2 # 使用者8852944140293

    因為涉及相容性問題,可以透過req.header("x-forwarded-for")與req.connection.remoteAddress來獲取IP地址,下面是封裝好的一個函式:

    function getClientIp(req) {

    var ipAddress;

    var forwardedIpsStr = req.header("x-forwarded-for");

    if (forwardedIpsStr) {

    var forwardedIps = forwardedIpsStr.split(",");

    ipAddress = forwardedIps[0];

    }

    if (!ipAddress) {

    ipAddress = req.connection.remoteAddress;

    }

    return ipAddress;

    };

  • 中秋節和大豐收的關聯?
  • NBA單場三分記錄是湯普森的14個三分,CBA的記錄是多少?是誰創造的?