Page 1 of 1

Only add if not found...

Posted: Wed Jul 01, 2009 4:20 pm
by Peuplarchie
Good day to you all,
My code is looking for user name in a file, if match found, do nothing, if no match found, add to list.

Right now, it add anyway !

Code: Select all

 
 
 
$activeadmlist = "user_list.txt";
$pos = strpos($activeadmlist, $_SESSION['username']);
 
if ($pos === false) {
 
$output= $_SESSION['username']."\n";
$newfile="user_list.txt";
$file = fopen ($newfile, "a");
fwrite($file, $output);
fclose ($file); 
 
 
} else {
    
 
} 
 
 
Thanks!

Re: Only add if not found...

Posted: Wed Jul 01, 2009 5:03 pm
by requinix
Having trouble with the advice you've been getting from other sites? How about what you got earlier?

I'll say the same thing. Again. For the millionth time.
$activeadmnlist is a string. It is not the contents of the file. If you want its contents then use file_get_contents.