Closed Thread Icon

Topic awaiting preservation: User Registration Script... Pages that link to <a href="https://ozoneasylum.com/backlink?for=12593" title="Pages that link to Topic awaiting preservation: User Registration Script..." rel="nofollow" >Topic awaiting preservation: User Registration Script...\

 
Author Thread
readonlynet
Obsessive-Compulsive (I) Inmate

From: Connecticut
Insane since: Jan 2003

posted posted 01-26-2003 03:29

Hello,

I need some help here. I am writing a script which invloves a User Registration. Ive made it so the names and other information is in a text file. Users can sign up, but theres one problem. Two of the same names can be registered (ie: brian, brian). I would like it so that the user can register with the same name as an already existing member. I have attempted to make it work, but i cant. So thats why im coming here.

Here is what im trying to do:
<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>$file = file("users.txt");
while(list(,$value)=each($file)){
list($name, $password2) = explode("

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-26-2003 14:42

just a wild guess, but after you explode() there might be some whitespace around $name... so try to replace strtolower($name) with strtolower(trim($name))

so long,

Tyberius Prime

readonlynet
Obsessive-Compulsive (I) Inmate

From: Connecticut
Insane since: Jan 2003

posted posted 01-26-2003 17:52

Okay, that did not work, but ive got it. I just put all the names in an array and used preg_grep() to check if the $user exists in the array. Heres the code:

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
function valid_name($usn, $arr) {
return preg_grep('/^' . preg_quote($usn, '/') . '$/i', $arr);
}

$file = file("user.txt");
foreach ($file as $c) {
list($name, $password2) = explode("

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-26-2003 19:37

You shouldn't need the preg_grep (since you're not using any of the features of a reg_exp) you can just use in_array;



.:[ Never resist a perfect moment ]:.

readonlynet
Obsessive-Compulsive (I) Inmate

From: Connecticut
Insane since: Jan 2003

posted posted 01-26-2003 20:33

yeah, but i wanted it to be case-insensitive. I found that little snippet in the php.net manual for in_array i believe. So i gave it a try and it worked out great.

yep:

quote:
case-insensitive version of in_array:

function is_in_array($str, $array) {
return preg_grep('/^' . preg_quote($str, '/') . '$/i', $array);
}



located at the bottom of the manual.

[This message has been edited by readonlynet (edited 01-26-2003).]

« BackwardsOnwards »

Show Forum Drop Down Menu