Gauntlet Posted September 27, 2009 Share Posted September 27, 2009 Hello there. I am trying to have my website log all ips. I have set up a php script to do this. <?php $v_ip = $REMOTE_ADDR; $v_date = date("l d F H:i:s"); $fp = fopen("ips.txt", "a"); fputs($fp, "IP: $v_ip - DATE: $v_date\n\n"); fclose($fp); ?> My html page executes the php script in the head but no text actually gets written in the ips.txt file. Any ideas? *UPDATE* I created a link in the body section of my website that launches the PHP script and it worked, it printed text to the ips.txt file but it didn't show the ip, it just showed: IP: - DATE: Sunday 27 September 06:39:37 So there is no ip where it is supposed to be. So now I have two problems. One is how do I have the php script automatically run when the web page is opened? And two, why doesn't the text file display the ip? Quote Link to comment https://forums.phpfreaks.com/topic/175681-solved-ip-address-logging/ Share on other sites More sharing options...
Zane Posted September 27, 2009 Share Posted September 27, 2009 Problem one: put the script at the top of page Problem two: it's $_SERVER['REMOTE_ADDR'] not $REMOTE_ADDR Quote Link to comment https://forums.phpfreaks.com/topic/175681-solved-ip-address-logging/#findComment-925768 Share on other sites More sharing options...
guyfromfl Posted September 27, 2009 Share Posted September 27, 2009 $v_ip = $_SERVER['REMOTE_ADDR']; Quote Link to comment https://forums.phpfreaks.com/topic/175681-solved-ip-address-logging/#findComment-925769 Share on other sites More sharing options...
Gauntlet Posted September 27, 2009 Author Share Posted September 27, 2009 Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/175681-solved-ip-address-logging/#findComment-925770 Share on other sites More sharing options...
Maq Posted September 27, 2009 Share Posted September 27, 2009 You should read the documentation on $_SERVER, may find some helpful information. Quote Link to comment https://forums.phpfreaks.com/topic/175681-solved-ip-address-logging/#findComment-925773 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.