REMOTE_ADDR is the most reliable/common, and can be trusted. However, it doesn't always show the correct IP if you're using a proxy. For that, you need HTTP_X_FORWARDED_FOR, but keep in mind that it can be spoofed, or contain dodgy values such as "unknown" or multiple IPs added by multiple proxies.
Very simple example that doesn't check if HTTP_X_FORWARDED_FOR is valid (I'm lazy
)...
code:
if($_SERVER['HTTP_X_FORWARDED_FOR']) {
echo $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
echo $_SERVER['REMOTE_ADDR'];
}