cloudll Posted January 15, 2012 Share Posted January 15, 2012 Hi guys. im using this line to log any users that log into my site. It writes to the log correctly however it doesn't leave a new a line. Can anyone see what ive done wrong with my code. thanks. fwrite($fh, $_SESSION['username'] . ' at ' . strftime('%c') . "\n"); Quote Link to comment https://forums.phpfreaks.com/topic/255077-writing-to-a-file-new-line-not-working/ Share on other sites More sharing options...
AyKay47 Posted January 15, 2012 Share Posted January 15, 2012 Really depends on what os you have, you may have to use "\r\n" Quote Link to comment https://forums.phpfreaks.com/topic/255077-writing-to-a-file-new-line-not-working/#findComment-1307924 Share on other sites More sharing options...
cloudll Posted January 15, 2012 Author Share Posted January 15, 2012 thanks, that worked. im using apache on windows 7 Quote Link to comment https://forums.phpfreaks.com/topic/255077-writing-to-a-file-new-line-not-working/#findComment-1307925 Share on other sites More sharing options...
AyKay47 Posted January 15, 2012 Share Posted January 15, 2012 Some os accept simply then newline character, some require the carriage return, some require both. Quote Link to comment https://forums.phpfreaks.com/topic/255077-writing-to-a-file-new-line-not-working/#findComment-1307932 Share on other sites More sharing options...
cloudll Posted January 15, 2012 Author Share Posted January 15, 2012 Would i need to change the code depending on what os i was using at the time? or could i leave it as \r\n and it would work no matter what the os? Quote Link to comment https://forums.phpfreaks.com/topic/255077-writing-to-a-file-new-line-not-working/#findComment-1307940 Share on other sites More sharing options...
AyKay47 Posted January 15, 2012 Share Posted January 15, 2012 Best bet is \r\n Quote Link to comment https://forums.phpfreaks.com/topic/255077-writing-to-a-file-new-line-not-working/#findComment-1307942 Share on other sites More sharing options...
laffin Posted January 15, 2012 Share Posted January 15, 2012 Use PHP_EOL fwrite($fh, $_SESSION['username'] . ' at ' . strftime('%c') . PHP_EOL); Quote Link to comment https://forums.phpfreaks.com/topic/255077-writing-to-a-file-new-line-not-working/#findComment-1307943 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.