When you say it doesn't work - do you mean you get nothing? Or do you mean you get an IP other than your end user's?
If you get nothing, try running phpinfo(); and see which var contains your IP.
If you get the wrong one, you're gonna have loads of trouble 'cause you're probably getting someone's proxy server...
Hope it helps.
J.