| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Sep 2005 Location: At Home
Posts: 881
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Unique IP I have a poll script but the only problem it has is that it will let me add more than one vote, I used a basic ip detection but that didn't work. Is there a way of getting the users real IP? This is what I have right now: PHP Code:
__________________ |
| |
| | #2 (permalink) |
| NamePros Member Join Date: May 2005
Posts: 102
![]() | In what way didn't it work? I think using IP address detection alone will not work 100%, primarily because of the way AOL uses proxies to route all their internet traffic. An AOL user is not guaranteed to have the same ip address for different images on a page, let alone two page requests. There is also the issue of 2 people from the same IP address. Companies may well route all their employees through a single router with one IP address. Frequently the forwarded-for and client-ip fields will not be filled in as it is considered a security risk (even though IP addresses and machine names get sent out in email headers from the same organisations). ????: NamePros.com http://www.namepros.com/showthread.php?t=195647 Using cookies as well may help. I'd be very interested to see what you come up with in the end. Regards, Mike |
| |
| | #3 (permalink) |
| NamePros Regular Join Date: Oct 2005 Location: Portugal
Posts: 800
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Code: function validip($ip) {
if (!empty($ip) && ip2long($ip)!=-1) {
$reserved_ips = array (
array('0.0.0.0','2.255.255.255'),
array('10.0.0.0','10.255.255.255'),
array('127.0.0.0','127.255.255.255'),
array('169.254.0.0','169.254.255.255'),
array('172.16.0.0','172.31.255.255'),
array('192.0.2.0','192.0.2.255'),
array('192.168.0.0','192.168.255.255'),
array('255.255.255.0','255.255.255.255')
);
foreach ($reserved_ips as $r) {
$min = ip2long($r[0]);
$max = ip2long($r[1]);
if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
}
return true;
} else {
return false;
}
}
function getip() {
if (validip($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
}
foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) {
if (validip(trim($ip))) {
return $ip;
}
}
if (validip($_SERVER["HTTP_X_FORWARDED"])) {
return $_SERVER["HTTP_X_FORWARDED"];
} elseif (validip($_SERVER["HTTP_FORWARDED_FOR"])) {
return $_SERVER["HTTP_FORWARDED_FOR"];
} elseif (validip($_SERVER["HTTP_FORWARDED"])) {
return $_SERVER["HTTP_FORWARDED"];
} elseif (validip($_SERVER["HTTP_X_FORWARDED"])) {
return $_SERVER["HTTP_X_FORWARDED"];
} else {
return $_SERVER["REMOTE_ADDR"];
}
}
__________________ Joćo Fernandes Silva |
| |
| | #4 (permalink) | ||||
![]() Join Date: Jul 2005 Location: Coffs H, Australia
Posts: 3,456
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Yes, in what way do you mean that you didn't get an IP? This should work in php:
__________________ Free Forums / GoDaddy Coupon Codes (NEW DOMAIN!) / Free Arcade Script / <?='Your computer is '.(1?fine:broken).'.'?> | ||||
| |
| | THREAD STARTER #5 (permalink) | ||||
| NamePros Regular Join Date: Sep 2005 Location: At Home
Posts: 881
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
__________________ | ||||
| |