http://www.perlmonks.org?node_id=171728

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

I am very relatively new to the PERL language. So please bear with me. I am creating a site which requires a login via .htaccess. I am trying to figure out how to read the ENV(“$REMOTE_USER”) variable to use the user name within the site.

Here is a small simple piece of script that I have tried which prints nothing at all.

-------------------------------------------------------- #!c:/www/perl/bin/perl.exe #-- This Displays errors to browser --# BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } $user = $ENV{"REMOTE_USER"}; print "<p>$user</p>"; --------------------------------------------------------

What is wrong?

Thanx,
FireDog69

Replies are listed 'Best First'.
Re: Getting REMOTE_USER from .htaccess
by cLive ;-) (Prior) on Jun 05, 2002 at 06:30 UTC
    The code works, but I thoroughly recommend you use strict and warnings now while you're still fresh and impressionable :)
    #!c:/www/perl/bin/perl.exe use strict; use warnings; use CGI::Carp('fatalsToBrowser'); $|=1; print "Content-type: text/html\n\n"; my $user = $ENV{"REMOTE_USER"}; print "<p>$user</p>";

    I don't use Perl on Win32, but my guess is (depending on which Perl you're using maybe) that either:

    • file associations aren't set up for .pl/pm files;
    • the path to Perl is screwy; or
    • your script's name does not end in a valid file extension.

    just my .02

    cLive ;-)

    oh, ps - you might also want to learn the CGI module as well :)

    --
    seek(JOB,$$LA,0);

Re: Getting REMOTE_USER from .htaccess
by schumi (Hermit) on Jun 05, 2002 at 09:23 UTC
    I second cLive;-)'s suggestion to look at the CGI-module. It lets you do the following:

    #!c:/www/perl/bin/perl.exe use strict; use warnings; use CGI qw/:standard/; use CGI::Carp('fatalsToBrowser'); print header(); # instead of putting print "Content-type: text/html\n\ +n"; print remote_user();

    Hope this helps...

    --cs

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

Re: Getting REMOTE_USER from .htaccess
by Juerd (Abbot) on Jun 05, 2002 at 07:49 UTC

    I am very relatively new to the PERL language.

    One important thing to learn is that there is no PERL. Perl is the language, perl is the interpreter.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      /me points to Acme::Inline::PERL... according to the POD:
      PERL is a programming language for writing CGI applications. It's main + strength is that it doesn't have any unnecessary warnings or strictu +res. It is a direct descendent of Perl, a programming language which +was used mainly by programmers. However, the original language required too muc +h reading and thinking and so PERL was developed as a language which +was more in tune with the requirements of the Internet age.
      jmcnamara++ for this one :)

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.