Jump to content


Photo

PHP Help


  • Please log in to reply
1 reply to this topic

#1 Millar

Millar
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • LocationSouthampton, UK.

Posted 18 March 2006 - 06:23 PM

Well, I was wondering if anyone could give me a script I can use to get a entered value from a post form (e.g Username) and check to see if the username exists in a plain txt file I have with usernames separated by a line break, thanks in advanced.
Millar.

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 18 March 2006 - 08:59 PM

This should work, assuming that each line is only the username.

$filename = "path/to/file.txt";
$username = $_POST['username'];

$file = file($filename);
if (in_array($username, $file)) {
  ...code for when the username is in the file...
} else {
  ...code for when the username is not in the file...
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users