KevinM1 Posted December 1, 2006 Share Posted December 1, 2006 For security reasons, I'd like to be able to get a user's IP address and check it against what's stored in a session variable to prevent hijacking. Unfortunately, I'm not sure if PHP can get access to a user's IP address, so this is a two-part question:Can PHP 5+ (I'm not sure what version I have access to beyond that thanks to GoDaddy's luddite-esque approach to hosting) gain access to a user's IP address without any addon or extension, as I don't have direct access to the php.ini file?If not, I'm planning on using JavaScript to get that info...what would you suggest for the cleanest (and most secure) way of getting that info into PHP's hands so it can use it with sessions? I'm thinking either a hidden input or a cookie, but I'd like to get some opinions on my choices.Thanks. :) Quote Link to comment https://forums.phpfreaks.com/topic/29134-ip-address/ Share on other sites More sharing options...
taith Posted December 1, 2006 Share Posted December 1, 2006 this should fix that problem :-)[code]<?function get_ip(){ if(!$ip=@$REMOTE_ADDR) $ip=$_SERVER['REMOTE_ADDR']; return $ip;}echo get_ip();?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29134-ip-address/#findComment-133559 Share on other sites More sharing options...
KevinM1 Posted December 1, 2006 Author Share Posted December 1, 2006 [quote author=taith link=topic=117013.msg477129#msg477129 date=1164996518]this should fix that problem :-)[code]<?function get_ip(){ if(!$ip=@$REMOTE_ADDR) $ip=$_SERVER['REMOTE_ADDR']; return $ip;}echo get_ip();?>[/code][/quote]Sweet! ;D I completely forgot about REMOTE_ADDR...d'oh! :blush: Quote Link to comment https://forums.phpfreaks.com/topic/29134-ip-address/#findComment-133561 Share on other sites More sharing options...
kenrbnsn Posted December 1, 2006 Share Posted December 1, 2006 Just remember that if a user from AOL accesses your site this will most likely break due to the way AOL handles IP addresses.Ken Quote Link to comment https://forums.phpfreaks.com/topic/29134-ip-address/#findComment-133588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.