File IO troubles

From: Date: Sat, 11 Aug 2001 20:30:58 +0000
Subject: File IO troubles
Groups: php.db 
Request: Send a blank email to php-db+get-11253@lists.php.net to get a copy of this message
I have been working on a chat system for a while now and I am now down to the last part: removing people from the "users list" when they leave. The following code is called by a JS when the user leaves: <?php setcookie ("cookie_logged", "", time()+2592000); $filepointer1 = fopen("middle_right.html", "r"); $Array = file ("middle_right.html"); fclose ($filepointer1); $filepointer2 = fopen("middle_right.html", "w"); $x = count($Array); for ($i=0; $i<=$x; $i++) { if ($Array[i] == "$uid<br>") { //The file it is checking right now, //middle_right.html is formatted //with a user id (uid) and then a //<br> fwrite ($filepointer2, ""); } else { fwrite ($filepointer2, $Array[i]); } } print "<body bgcolor='#000000'>"; print "<font color='FFFFFF'"; print "YOU HAVE BEEN LOGGED OUT"; print "</font>"; fclose ($filepointer2); ?> The problem is that when called, this script deletes the entire file rather than sorting through it and removing the username of the person that just left.

« previous php.db (#11253) next »