jane65 Posted June 5, 2013 Share Posted June 5, 2013 Hi, I installed an auction script that was running fine for a couple of days, but today when I went to the website there are warning errors displaying. I'm not sure if it is the script at fault or if my server has altered something that has affected the script as the server went down yesterday, and today was the first time I'd looked at the website since then. It just seems strange how it was running ok before now. The site doesn't have any users as yet except for me. I've found the part of the script that I think the warnings relate to, and pasted it below and hoping that someone here may be able to help me or tell me why this has happened. Thanks in advance for any help. Warning: fopen(online_users.txt) [function.fopen]: failed to open stream: Permission denied in /home/site/public_html/includes/functions.php on line 751 Warning: flock() expects parameter 1 to be resource, boolean given in /home/site/public_html/includes/functions.php on line 752 Warning: fwrite(): supplied argument is not a valid stream resource in /home/site/public_html/includes/functions.php on line 759 function online_users($in_admin = false) { $data_file = (($in_admin) ? '../' : '') . 'online_users.txt'; $session_time = 60; //time in **minutes** to consider someone online before removing them if(!file_exists($data_file)) { $fp = fopen($data_file, 'w+'); fclose($fp); } $ip = $_SERVER['REMOTE_ADDR']; $users = array(); $online_users = array(); //get users part $fp = fopen($data_file, 'r'); flock($fp, LOCK_SH); while(!feof($fp)) { $users[] = rtrim(fgets($fp, 32)); } flock($fp, LOCK_UN); fclose($fp); //cleanup part $x = 0; $already_in = false; foreach($users as $key => $data) { list( , $last_visit) = explode('|', $data); if(CURRENT_TIME - $last_visit >= $session_time * 60) { $users[$x] = ''; } else { if(strpos($data, $ip) !== false) { $already_in = true; $users[$x] = $ip . '|' . time(); //update record } } $x++; } if($already_in == false) { $users[] = $ip . '|' . time(); } //write file $fp = fopen($data_file, 'w+'); flock($fp, LOCK_EX); $nb_users = 0; foreach($users as $user) { if(!empty($user)) { fwrite($fp, $user . "\r\n"); $nb_users++; } } flock($fp, LOCK_UN); fclose($fp); if ($in_admin) { $nb_users--; $nb_users = ($nb_users < 0) ? 0 : $nb_users; } return $nb_users; } Quote Link to comment https://forums.phpfreaks.com/topic/278808-need-help-to-fix-warning-errors/ Share on other sites More sharing options...
Jessica Posted June 5, 2013 Share Posted June 5, 2013 The 2nd and 3rd are because of the 1st. Did you check the permissions of the online_users.txt file? Quote Link to comment https://forums.phpfreaks.com/topic/278808-need-help-to-fix-warning-errors/#findComment-1434268 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.