Jump to content

Need help to fix Warning Errors


jane65

Recommended Posts

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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.