Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Username for later use?

nearlycanadiannearlycanadian Member Posts: 14
I'm hoping someone can help me out once again. I have successfully implemented multiple user password protection on a directory of mine on a UNIX server (using .htaccess and .htpasswd). What I would like to know is how I can grab the username of the person when they log in and use it in other ways. Specifically, I need create a file based on the username, and possibly post a message to a private board with the username already filled in. Is this possible in Unix or would I have to implement this using Java or Perl? Thanks a bunch for reading this!

Comments

  • JonathanJonathan Member Posts: 2,914
    : I'm hoping someone can help me out once again.
    Well, I can try... :-)

    : I have successfully implemented multiple user password protection on
    : a directory of mine on a UNIX server (using .htaccess
    : and .htpasswd). What I would like to know is how I can grab the
    : username of the person when they log in and use it in other ways.
    : Specifically, I need create a file based on the username, and
    : possibly post a message to a private board with the username already
    : filled in. Is this possible in Unix or would I have to implement
    : this using Java or Perl? Thanks a bunch for reading this!
    What do you mean by "is this possible in Unix"? Yes it is, but UNIX is an operating system that runs programs such as Perl or the JAVA VM. I kinda don't see the comparison. Unless you're talking about shell scripting?

    Good news is that if you're writing a CGI of some sort then the web server puts the username of the currently logged in user in the REMOTE_USER environment variable. E.G. try this Perl CGI:-

    [code]#!/usr/bin/perl

    #Print HTTP header.
    print "Content-type: text/html

    ";

    #Show the username.
    print "You are currently logged in as $ENV{'REMOTE_USER'}.
    ";
    [/code]

    Hope this helps,

    Jonathan

    ###
    # Example Of Perl 6 Syntax.
    push @will, my Power $button;
    my $hardware is Useless but Valuable;
    do ($nothing) while $i.work and print $stuff;
    push (@will, my Off $button) and die "with me";

  • nearlycanadiannearlycanadian Member Posts: 14
    : What do you mean by "is this possible in Unix"? Yes it is, but UNIX is an operating system that runs programs such as Perl or the JAVA VM. I kinda don't see the comparison. Unless you're talking about shell scripting?
    : Good news is that if you're writing a CGI of some sort then the web server puts the username of the currently logged in user in the REMOTE_USER environment variable.

    I know that Unix is an operating system, and that Perl is a program. I guess I used "improper techie grammar" in my last post. :^)

    Here is a scenario: A user logs on (whom I have set up via .htaccess and .htpasswd) to my private directory. They fill out forms, the results of which will be stored in a filename that is their username. That's why I was wondering if it was possible to take the username of the person logged on to the Unix directory and store it in a variable for later use.

    I hope this clarifies my question somewhat. I'll try out your code and see how it goes. Thanks very much!
  • JonathanJonathan Member Posts: 2,914
    : I know that Unix is an operating system, and that Perl is a
    : program. I guess I used "improper techie grammar" in my last
    : post. :^)
    No worries...just got momentarily confused. Easily done...

    : Here is a scenario: A user logs on (whom I have set up
    : via .htaccess and .htpasswd) to my private directory. They fill out
    : forms, the results of which will be stored in a filename that is
    : their username. That's why I was wondering if it was possible to
    : take the username of the person logged on to the Unix directory and
    : store it in a variable for later use.
    You got lucky; you don't have to store it because the web browser sends it with every request and the web server (Apache) passes it on through the environment variable.

    : I hope this clarifies my question somewhat. I'll try out your code
    : and see how it goes. Thanks very much!
    Yes, I'm pretty much sure that it will do what you want. Note that it only works when the script is ran from inside a password protected area. E.G. you can't have:-

    /aprotectedfolder/files
    /cgi-bin/thescript.pl

    And expect it to work unless the root directory is protected.

    Jonathan

    ###
    # Example Of Perl 6 Syntax.
    push @will, my Power $button;
    my $hardware is Useless but Valuable;
    do ($nothing) while $i.work and print $stuff;
    push (@will, my Off $button) and die "with me";

Sign In or Register to comment.