0

My online chat uses a php script. There`s the part I need to correct

if(isset($_SESSION['name']) && $_POST['text'] != ""){
	$search = "";
	$aname = $_SESSION['name'];
	function find_value($input) {
		$handle = fopen("online.html", "r");
		if ($handle) {
 		 while (!feof($handle)) {
  		  $entry_array = explode(" ",fgets($handle));
   		 if ($entry_array[0] == $input) {
    			  $search = $entry_array[0];
     		 }
   		 }
 		 fclose($handle);
  		}
RETURN NULL;
}
	find_value($aname);
	if($search == "") {
	$handle = fopen("online.html",'r');
	$contents = fread($handle,filesize("online.html"));
	fclose($handle);
	$handle = fopen("online.html",'w');
	fwrite($handle,$contents." <BR> ".$_SESSION['name']);
	fclose($handle);
	}

My problem is, so when somebody submits a message, his name is written into online.html as many times, as he writes something. But i need to write it only ones, because all that names in online.html will appear on my site as logged in users. Please help me to correct it. I need to all names appear in online.html only once.

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo
0

I don't really follow, but if you have an array of users, you can check to see if they're in it with in_array(). If not you can add an user with array_push().

0

Hi Tomashqooo,

Are you adding them to the online list every time they post something? If you add them to the list when they login, they will only get added once.

0

Like ardav said you could use array where username is key and his status be value like evstevemd=>idle
and use

if(!array_key_exists($username)){
    array[$key] = "active";
}

Nothing tested, but just to give an idea!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.