Only add if not found...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Only add if not found...

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Only add if not found...

Post 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.
Post Reply