Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get current username who in the system in cgi?

I have tried using,

PERL
my $system_user = $cgi_obj->remote_user;


and also

PERL
my $system_user = $ENV{REMOTE_USER};


But nothing works. Please help. Thanks in advance.
Posted
Updated 27-Mar-14 23:38pm
v3

If you are trying to get the username who is running the CGI execution, you can use the following.

PERL
my $username = $ENV{LOGNAME};


or you can combine multiple options to make sure one of them return a valid data.

PERL
my $username = $ENV{LOGNAME} || getpwuid($<) || $ENV{USER}; 
 
Share this answer
 
It looks like you are trying to determine the identity of an unauthenticated remote user, which does not work and even if it did would be meaningless. http by default is anonymous. To change this you need to either authenticate the user (http authentication sets the variables you were looking at) or track the user (consult your lawyer and priest before tracking users). Consult the manual for your authentication or tracking method for further details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900