mynamesleo Posted November 4, 2006 Share Posted November 4, 2006 Hi all,Is it alot of work to get a users IP from a form? for example, in a basic form which would sendthe string from a textbox to a text file somewhere when Submit is pressed, how could I go aboutsending the users IP also? so string:ip would be sent to the text file. Quote Link to comment https://forums.phpfreaks.com/topic/26148-users-ip-submit/ Share on other sites More sharing options...
joshi_v Posted November 4, 2006 Share Posted November 4, 2006 First get the IP address of the user and then assign it to a variable.[code]<?php$domain = GetHostByName($REMOTE_ADDR); ?>[/code]pass this value to a hidden variable.[code]<input type="hidden" name="domain" value="<?php echo $domain;?>"[/code]when u submit the form this value is also getting passed. so u can use there..another option is , storing IP address in a session variable. so you can use any where in your scripts. Quote Link to comment https://forums.phpfreaks.com/topic/26148-users-ip-submit/#findComment-119559 Share on other sites More sharing options...
mynamesleo Posted November 4, 2006 Author Share Posted November 4, 2006 wow I was expecting a messy job, thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/26148-users-ip-submit/#findComment-119561 Share on other sites More sharing options...
toplay Posted November 4, 2006 Share Posted November 4, 2006 The $REMOTE_ADDR varible relies on register_globals to be on. Use $_SERVER['REMOTE_ADDR'] variable instead.If you just want to capture the persons, IP address then there's no reason to put it in the form (as a hidden field) to begin with. Just grab it after the form is submitted.Please note that getting the real IP address is a little more complicated that just using that one server variable (because of proxy use). Quote Link to comment https://forums.phpfreaks.com/topic/26148-users-ip-submit/#findComment-119619 Share on other sites More sharing options...
brendandonhue Posted November 4, 2006 Share Posted November 4, 2006 Putting it in a hidden form field allows to the user to submit any value they want. You should grab $_SERVER['REMOTE_ADDR'] directly in your script. Quote Link to comment https://forums.phpfreaks.com/topic/26148-users-ip-submit/#findComment-119636 Share on other sites More sharing options...
wildteen88 Posted November 4, 2006 Share Posted November 4, 2006 Also keep in mind $_SERVER['REMOTE_ADDR'] will not get the users true IP address if they being a proxy or if their ISP dishes out dynamic IP Addresses. Quote Link to comment https://forums.phpfreaks.com/topic/26148-users-ip-submit/#findComment-119639 Share on other sites More sharing options...
brendandonhue Posted November 4, 2006 Share Posted November 4, 2006 It will always give you the IP that your server is communicating with, not sure what else you would expect. Quote Link to comment https://forums.phpfreaks.com/topic/26148-users-ip-submit/#findComment-119723 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.