How can I get the user's IP address? Is there a function for it? I want to use it for things like banning offenders from my site, displaying certain content to certain users (like admins or thread-starters for example), or redirecting a user to a certain page depending on their IP.
Thanks if you can help.
Joe
Yet another simple question on IP's
Moderator: General Moderators
-
joetheeskimo5
- Forum Commoner
- Posts: 43
- Joined: Sun Dec 14, 2003 4:47 pm
- Location: US
- Contact:
Code: Select all
<?php
$usersIP = $_SERVER["REMOTE_ADDR"];
?>-
joetheeskimo5
- Forum Commoner
- Posts: 43
- Joined: Sun Dec 14, 2003 4:47 pm
- Location: US
- Contact:
This is not recommended using just their IP. IP's are dynamic and I've heard that AOL users may even have a different IP everytime they do a http request. You are better off using sessions or cookies.displaying certain content to certain users (like admins or thread-starters for example)
Banning people by IP's may work for a little, but it won't stop a determined user.
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
For getting the IP address of the user, I use this bit of code I stole from somewhere.
But I use this in conjunction with sessions, which is why REMOTE_ADDR is third. Because if the user's IP address keeps changing (due to multiple proxy servers, for example), then session verification with IP isn't so great.
Code: Select all
<?php
// Get user's IP address.
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
else $ip = "UNKNOWN";
?>fyi: anyone malicious in a wya they can be a detriment is likely toknow how to use a proxy, therefore ip isn't a big help. add to that unless you ban by domain blocks, they will get a new one each time if they are on dial up. there's also other issues that make ip banning something that should be a lst resort at best.
find someething else to do to ban a user.'
i decided to do so by email address.
yeah, easy enough to sign up with a new one, but after a while they will tire of it. but i also keep certain other information that once they get to a few dozen ignups i can get their isp to drop them, and any subsequent ones as well for breach of terms of service
find someething else to do to ban a user.'
i decided to do so by email address.
yeah, easy enough to sign up with a new one, but after a while they will tire of it. but i also keep certain other information that once they get to a few dozen ignups i can get their isp to drop them, and any subsequent ones as well for breach of terms of service