Jump to content

IP address


KevinM1

Recommended Posts

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. :)
Link to comment
Share on other sites

[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:
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.