PDA

View Full Version : ثبت IP کاربران هنگام عضویت در سایت



LostOfMind
چهارشنبه 09 اسفند 1391, 22:10 عصر
سلام به دوستان.
کسی میدونه چطور میشه هنگام ثبت نام آی پی کاربران هم ثبت بشه تا دیگه کسی نتونه با یک آی پی ثبت نام
کنه؟

meisam3322
چهارشنبه 09 اسفند 1391, 22:32 عصر
با این کد میتونی آی پی کاربر رو بدست بیاری ، خیلی راحت بصورت string توی بانک ذخیره کن.




<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onload = function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://jsonip.appspot.com/?callback=DisplayIP";
document.getElementsByTagName("head")[0].appendChild(script);
};
function DisplayIP(response) {
document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;
}
</script>
</head>
<body>
<form>
<span id = "ipaddress"></span>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onload = function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://jsonip.appspot.com/?callback=DisplayIP";
document.getElementsByTagName("head")[0].appendChild(script);
};
function DisplayIP(response) {
document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;
}
</script>
</head>
<body>
<form>
<span id = "ipaddress"></span>
</form>
</body>
</html>

meisam3322
چهارشنبه 09 اسفند 1391, 22:41 عصر
این هم کدش با ASP.NET ولی همون کد اولی JSon جواب میده:



string visitorIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];


if (String.IsNullOrEmpty(visitorIPAddress))
visitorIPAddress = Request.ServerVariables["REMOTE_ADDR"];

if (string.IsNullOrEmpty(visitorIPAddress))
visitorIPAddress = Request.UserHostAddress;