droidus Posted July 17, 2011 Share Posted July 17, 2011 how would i record a user's information (browser info., ip address) to a text file? Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/ Share on other sites More sharing options...
teynon Posted July 17, 2011 Share Posted July 17, 2011 <?php $handle=fopen("myfile.txt", "a+"); fwrite($handle, $_SERVER['REMOTE_ADDR']); fclose($handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1243922 Share on other sites More sharing options...
droidus Posted July 17, 2011 Author Share Posted July 17, 2011 so why can't i write server information with this code?: <?php $filename = 'file.txt'; $somecontent = $_SERVER['REQUEST_TIME']; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote \"$somecontent\" to file \"$filename\""; fclose($handle); } else { echo "The file, \"$filename\" is not writable"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1243936 Share on other sites More sharing options...
teynon Posted July 17, 2011 Share Posted July 17, 2011 What happens? Is it saying file is not writable? If so, you need to chmod the file or directory. Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1243942 Share on other sites More sharing options...
AyKay47 Posted July 18, 2011 Share Posted July 18, 2011 What errors/messages do you receive. A little lore information would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1243968 Share on other sites More sharing options...
chintansshah Posted July 18, 2011 Share Posted July 18, 2011 Hello Drodious, Please write error_reporting(E_ALL); at line number 2 and reply back with error. Regards, Chintan Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1243993 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 <?php $handle=fopen("myfile.txt", "a+"); fwrite($handle, $_SERVER['REMOTE_ADDR']); fclose($handle); ?> Can be also done with a oneliner: file_put_contents('myfile.txt', $_SERVER['REMOTE_ADDR'], FILE_APPEND); Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1243995 Share on other sites More sharing options...
ZulfadlyAshBurn Posted July 18, 2011 Share Posted July 18, 2011 you didnt specify $handle ? Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1244027 Share on other sites More sharing options...
droidus Posted July 20, 2011 Author Share Posted July 20, 2011 Hello Drodious, Please write error_reporting(E_ALL); at line number 2 and reply back with error. Regards, Chintan i get : Notice: Undefined index: REQUEST_TIME in /homepages/.../.../htdocs/uploader/test2.php on line 4 Success, wrote "" to file "file.txt" line 4 contains: "$somecontent = $_SERVER['REQUEST_TIME'];" Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1245225 Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 your server is probably not configured for this then, you will need to contact you host about this issue Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1245234 Share on other sites More sharing options...
dcro2 Posted July 20, 2011 Share Posted July 20, 2011 You could just use time instead of REQUEST_TIME. It's pretty much the same thing. $somecontent = time(); Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1245235 Share on other sites More sharing options...
droidus Posted July 21, 2011 Author Share Posted July 21, 2011 why can't i do this?: $somecontent = "<br>" . date("F j, Y, g:i a"); Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1245462 Share on other sites More sharing options...
TeNDoLLA Posted July 21, 2011 Share Posted July 21, 2011 You can use it. Just use in date_default_timezone_set() to get correct time (if it is not already correct). Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1245522 Share on other sites More sharing options...
Porl123 Posted July 21, 2011 Share Posted July 21, 2011 Also text files don't recognise <br> tags as line breaks, as that is a html tag. Use this instead: $somecontent = "\n" . date("F j, Y, g:i a"); Quote Link to comment https://forums.phpfreaks.com/topic/242230-recording-ip-address-other-data/#findComment-1245528 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.