Only Once...

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
ACE55555
Forum Newbie
Posts: 1
Joined: Sat Sep 07, 2002 9:33 pm

Only Once...

Post by ACE55555 »

I am wondering how I can check to see if someone's name is already in the file, and if so, not re-enter their name. If it isn't, I want it to enter the name. Currently it enters the name repeatedly upon reloading. Surely there is a way to search the text file and do this...
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Usernames.txt

Code: Select all

John,Stephen,Mac,Takuma,Pep
Code

Code: Select all

<?php
$fh = fopen("usernames.txt","r");
$content = fread($fh,filesize($fh));
$content = explode(",",$content);
for($i = 0; $i <= count($content); $i++) {
  if($contentї$i] == $_POSTї"username"]) {
    //Username already exists
  } else {
    //Username do not exist in the file
  }
}
fclose($fh);
?>
Post Reply