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".
In reply to Re: Accessing a file from the perl
by abcdefg
in thread Accessing a file from the perl
by abcdefg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |