in reply to Accessing a file from the perl
I have a client and server application.MY client is sending the username(which it gets through getlogin()) to server.I want server to save all the registered username in a file called username.On receiving the request from client,it checks the username of client in the file and if it founds it ,its gives him permission to go ahead otherwise rejects it. here is what i did:
$user = <$client_socket>; chop($user); #remove the \n print "$prefix USER = $user\n"; unless (open (USERNAME, "username")) { print "ERROR:Cannot open username file.\n"; exit(1); # ERROR } while(<USERNAME>) { my @newusername = <USERNAME>; foreach $name (@newusername) { if($name ne $user) { print $client_socket "ERR\n"; print "$prefix ERROR: user $user not permitted to use this mode +. Exiting.\n"; close(USERNAME); exit(1); } } } #else, continue print $client_socket "ACK\n"; # approve the user. Limit this in + the future. close(USERNAME);
this isnt working as even when the file username has client name it is giving "user $user not allowed".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Accessing a file from the perl
by Eliya (Vicar) on Jan 11, 2012 at 23:24 UTC | |
by abcdefg (Acolyte) on Jan 12, 2012 at 00:03 UTC | |
by Eliya (Vicar) on Jan 12, 2012 at 00:11 UTC | |
by abcdefg (Acolyte) on Jan 12, 2012 at 00:22 UTC |