http://qs1969.pair.com?node_id=140396

NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: get user name
by redsquirrel (Hermit) on Jan 21, 2002 at 19:53 UTC
    You could try $ENV{REMOTE_USER}. Not sure how generic that is, but it works on our Solaris boxes.

    --Dave

      $ENV{REMOTE_USER} will work as long as some sort of basic authentication has been performed (IE those times when a little box pops up on the users browser asking them for a user and password). For example if you are restricting part of your site with .htpassword files or using AuthCookie etc.

      However if the area of the site is public or a more complex authentication is in place (ie nice cute forms with submit buttons) then $ENV{REMOTE_USER} will remain undefined.

      ---If it doesn't fit use a bigger hammer

        Thanks for the helpful explanation vagnerr. The tidbits of useful knowledge that come from posts like yours are one of the great values that PM provides.

        ++ to you!
        --Dave

Re: get user name
by schumi (Hermit) on Jan 21, 2002 at 21:42 UTC
    If the person logged on to a .htaccess-wise protected website, and your script is using CGI.pm, remote_user() should also do the trick.

    However, this doesn't work if you're wanting to get the username of a person logged on to a network (i.e. not onto a webserver).

    --cs

    There are nights when the wolves are silent and only the moon howls. - George Carlin

Re: get user name
by thunders (Priest) on Jan 21, 2002 at 19:19 UTC
    Update:I rephrased my answer

    Exactly what kind of network are we talking about here?

Re: get user name
by z3d (Scribe) on Jan 21, 2002 at 23:47 UTC
    Not that you've probably had a chance to get back to all of these suggestion, but I agree with a previous post - it all depends on the circumstances. Can you get us more information on the environment, both where you want to place the perl application and what kind of network it will live on? I know that in the past I've used the LDAP module to get user information against the Microsoft Directory server or Netscape's LDAP server, but in both cases it was based on some combination of $ENV{YADA} variables. If this isn't coming through a web server, it does get more difficult.

    That said, I notice you mentioned cgi or asp, so I guess it is coming through a web server =:) Check out the ENV variables that are available. You may not be able to get the exact username if it hasn't been authenticated, but you may be able to pull something else out that is unique. For instance, if this is a closed and limited system, you will be able to get their machine name, which in closed networks tends to be a unique identifier.

    Consider anything you might see in a web server log and that will get you close to a solution.

    z3d

      Thought of one more thing to add (I know, it's bad when you reply to your own reply) - you mentioned ASPs, which implies an MS network. IF I remember right, and it's been a long time, ASP's at least (can't remember if this is an MS specific thing or if it was in the ENV variables) can grab the network logon name from the incoming user - assuming your application is on an MS network, MS server, etc. ***************************************************************
      Zed? Zed's dead, baby, Zed's dead.
      Thought of one more thing to add (I know, it's bad when you reply to your own reply) - you mentioned ASPs, which implies an MS network. IF I remember right, and it's been a long time, ASP's at least (can't remember if this is an MS specific thing or if it was in the ENV variables) can grab the network logon name from the incoming user - assuming your application is on an MS network, MS server, etc. ***************************************************************<br< Zed? Zed's dead, baby, Zed's dead.