malda Posted July 28, 2009 Share Posted July 28, 2009 hi, i got a strange problem with php. i made a kind of logbook system using a file called log.php i got a file called logging.php that i include in the pages that need not be logged. <?php function logtofile($msg) { $userIp = ( isset($_SERVER['REMOTE_ADDR']) && ($_SERVER['REMOTE_ADDR'] != "")) ? $_SERVER['REMOTE_ADDR'] : "Unknown"; $actualTime = date("d/m/Y H:i:s"); $file = "log.php"; $log = "[" . $actualTime . "] : [" . $_SESSION['user'] . "] : [" . $userIp . "] : " . $msg . "<br>"; file_put_contents($file, $log, FILE_APPEND); } ?> it works fine but theire is one page that deals with mysql "DELETE...." and theire get the error Warning: file_put_contents(log.php) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/myaccount/wwwroot/test/admin/logger.php on line 11 my permissions are set good (as far i know) my webserver user is owner of the file log.php and it is set to chmod 644 (also tried to set it to 777 but it doesn't help) i already searched alot of webpages but no-one seems to have the problem that it doesn't work at one page only. if theire is anybody who has any ideas, please let me know MODIFIED: the code that refuses is logtofile("ERROR delteing sid 'not empty' for sid ---> '" . $_POST['sid_dropdown'] . "'"); Link to comment https://forums.phpfreaks.com/topic/167776-file_put_contents-sometimes-working/ Share on other sites More sharing options...
trq Posted July 28, 2009 Share Posted July 28, 2009 Your logtofile() attempts to write to the directory where the function is called. Does the script where you call logtofile() reside in a directory which is writable by your server? Normally, you would have your log files stored in one central location. Link to comment https://forums.phpfreaks.com/topic/167776-file_put_contents-sometimes-working/#findComment-884735 Share on other sites More sharing options...
malda Posted July 28, 2009 Author Share Posted July 28, 2009 the files loggin.php and log.php are in my /wwwroot/admin folder the page that doesn't work is in /wwwroot/admin/sid but theire is another php file in the sid folder that works fine (chmod of sid is 775) Link to comment https://forums.phpfreaks.com/topic/167776-file_put_contents-sometimes-working/#findComment-884740 Share on other sites More sharing options...
trq Posted July 28, 2009 Share Posted July 28, 2009 And who owns the sid directory? 775 means you only have read and execute permissions set for other. Link to comment https://forums.phpfreaks.com/topic/167776-file_put_contents-sometimes-working/#findComment-884743 Share on other sites More sharing options...
malda Posted July 28, 2009 Author Share Posted July 28, 2009 me not the webserver user Link to comment https://forums.phpfreaks.com/topic/167776-file_put_contents-sometimes-working/#findComment-884746 Share on other sites More sharing options...
trq Posted July 28, 2009 Share Posted July 28, 2009 Theres your problem then. Link to comment https://forums.phpfreaks.com/topic/167776-file_put_contents-sometimes-working/#findComment-884748 Share on other sites More sharing options...
malda Posted July 28, 2009 Author Share Posted July 28, 2009 i changed the owner of the sid folder to my webserver user. it didn't fix the problem theire is another php file in the folder of sid that works fine on my log script Link to comment https://forums.phpfreaks.com/topic/167776-file_put_contents-sometimes-working/#findComment-884753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.