>> >> $users[]=$newuser;
>> >> # adds the new user to the end of the above created users array
>> >> # then write the array to the file
>> >> $fd = fopen (".users", "w+");
>> >> fwrite ($fd, join("\n",$users));
>> >> fclose ($fd);
>> >>
>> >> the problem is after adding users, only the last user returns the user
>> >> name in the array, all the other users have an additional "/n" at the
>> >> end of them, which causes the check to barf.
>> >
>> >Well, if you RTFM, you'll know that file() "returns the file in an array
>> > ... with the newline still attached". So one possible solution is after
>> > using file(), loop through $users and remove the trailing "\n".
>> thanks, I am/was looking to avoid looping through the array unnecessarily,
>> and simply have them removed at the time of dumping the file into the
>> array.
>Then use:
>  if(in_array($HTTP_SERVER_VARS["REMOTE_USER"] . "\n", $users)) { ... }

leaving that last user added to the file not to match since it will not have a
\n at the end of it...

adding one to the user as it is added into the array results in yet another
array element after the file() since it reads the additional line as another
array element.

>BTW, it should be:
>  fwrite ($fd, join('', $users));
>otherwise each time you write the file out it will have an increasing number
>of "\n" attached to each user.

thats the crux...
        fwrite ($fd, join('', $users));
results in a long string of usernames in the, which can't be grabbed back into
the array with the file...  in short, there is no way to trim as you file() to
eliinate this (from what i can see) other than running it through each() or
something and rebuilding the array after trimming.  Was hoping for something a
little more eloquent.



PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to