如何使用经典ASP定义IP地址 [英] how to define the IP address using classic ASP

查看:69
本文介绍了如何使用经典ASP定义IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要一个完整的代码,每次用户登录到我的网站时如何获取/定义IP地址,因为我需要将IP地址保存到数据库表中以跟踪IP的来源.谢谢.

I just need a fully code how to get/define the IP address for every time user login into my website because i need to save the IP address into the database table for keep track where the IP comes. Thanks.

推荐答案

最好调用这样的简单函数:

You're better off calling a simple function like this:

Function IP()
    Dim strIP : strIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR") 
    If strIP = "" Then strIP = Request.ServerVariables("REMOTE_ADDR")
    IP = strIP
End Function

这将返回用户的真实IP地址,即使他们位于代理后面或通过CDN提供服务(有时可能会导致问题).

This will return the true IP address of the user, even if they're behind a proxy or being served through a CDN which can sometimes cause an issue.

这篇关于如何使用经典ASP定义IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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