Page 1 of 1

Yet another simple question on IP's

Posted: Sat Jan 17, 2004 4:13 pm
by joetheeskimo5
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

Posted: Sat Jan 17, 2004 4:17 pm
by Gen-ik

Code: Select all

<?php

$usersIP = $_SERVER["REMOTE_ADDR"];

?>

Posted: Sat Jan 17, 2004 4:18 pm
by scorphus
$_SERVER['REMOTE_ADDR']

RTM

Posted: Sat Jan 17, 2004 4:19 pm
by joetheeskimo5
Holy crap, you guys replied fast!

Thanks btw.

Joe :)

Posted: Sat Jan 17, 2004 9:49 pm
by DuFF
displaying certain content to certain users (like admins or thread-starters for example)
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.

Banning people by IP's may work for a little, but it won't stop a determined user.

Posted: Sat Jan 17, 2004 10:17 pm
by Gen-ik
BTOpenworld (UK) also change the users IP everytime they connect as well, so as DuFF said don't expect it to be very reliable.

Posted: Sat Jan 17, 2004 10:21 pm
by microthick
For getting the IP address of the user, I use this bit of code I stole from somewhere.

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";
?>
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.

Posted: Sun Jan 18, 2004 1:20 am
by m3rajk
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