inferium Posted December 16, 2008 Share Posted December 16, 2008 Hello, PHP n00blet here (though I'm starting to understand the language a bit better as of late). My boss wants me to be able to capture our clients' IP address in our online application here: http://apply.eliteautoweb.com. The form is made in html, as I don't know how to do PHP forms yet. So far in my searching, I've found the following snippet of code: <? $logged_string = "$REMOTE_ADDR|" . date("j M Y g:i a"); $file = fopen("userIP.log", "a"); fputs($file, $logged_string, strlen($logged_string)); fclose($file); ?> Is there a way that I can capture an IP address within the form using this code, or is there another more efficient way to capture IP? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/137225-solved-how-to-capture-ip-address/ Share on other sites More sharing options...
Jabop Posted December 16, 2008 Share Posted December 16, 2008 <?php $ip_address = $_SERVER['REMOTE_ADDR']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137225-solved-how-to-capture-ip-address/#findComment-716858 Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 This will give you the users IP: $_SERVER['REMOTE_ADDR']; Quote Link to comment https://forums.phpfreaks.com/topic/137225-solved-how-to-capture-ip-address/#findComment-716859 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 <?php $logged_string = $_SERVER['REMOTE_ADDR'] . "|" . date("j M Y g:i a"); $file = fopen("userIP.log", "a"); fputs($file, $logged_string, strlen($logged_string)); fclose($file); ?> That is the proper usage, $REMOTE_ADDR assumes register_globals is on, which is should be off due to security risks. Use $_SERVER to access it instead. As far as that, it should capture and IP just fine and write it to a log file, or if you have a database make a field called IP and save it to the database. Quote Link to comment https://forums.phpfreaks.com/topic/137225-solved-how-to-capture-ip-address/#findComment-716860 Share on other sites More sharing options...
inferium Posted December 16, 2008 Author Share Posted December 16, 2008 Sweet deal So I'm guessing there is no way to have the address sent as a part of the application? Having a unique IP for each of our clients is the main goal I am trying to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/137225-solved-how-to-capture-ip-address/#findComment-716863 Share on other sites More sharing options...
Jabop Posted December 16, 2008 Share Posted December 16, 2008 Sweet deal So I'm guessing there is no way to have the address sent as a part of the application? Having a unique IP for each of our clients is the main goal I am trying to accomplish. I think that's a very vague question. What do you mean "sent" as part of the "application?" You can put the IP address in a hidden input field. <input type="hidden" name="ip_address" value="<?=$_SERVER['REMOTE_ADDR']?>" /> and handle that through your post/get vars, or, you can just get the IP as we all have already explained. Quote Link to comment https://forums.phpfreaks.com/topic/137225-solved-how-to-capture-ip-address/#findComment-716865 Share on other sites More sharing options...
inferium Posted December 16, 2008 Author Share Posted December 16, 2008 Ah great! Thank you guys so much, this is really helpful Quote Link to comment https://forums.phpfreaks.com/topic/137225-solved-how-to-capture-ip-address/#findComment-716879 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.