Peuplarchie Posted July 1, 2009 Share Posted July 1, 2009 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 ! $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! Quote Link to comment Share on other sites More sharing options...
AwptiK Posted July 4, 2009 Share Posted July 4, 2009 strpos is treating $activeadmlist as a string, not a file. You never specified that you were opening a file or getting it's contents. So it's checking in "user_list.txt" for the username, that's why it's adding anyway. //grabs contents of the actual file $file = file_get_contents("user_list.txt"); $user = $_SESSION['username']; if(!strpos($file, $user)) { $output= $user."\n"; $newfile="user_list.txt"; $file = fopen ($newfile, "a"); fwrite($file, $output); fclose ($file); } else {} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.