Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: RE: Getting username and password from the URL.

by Punto (Scribe)
on Jun 12, 2000 at 06:33 UTC ( [id://17658]=note: print w/replies, xml ) Need Help??


in reply to RE: Getting username and password from the URL.
in thread Getting username and password from the URL.

If you are using mod_perl, try this:

The server is running mod_perl (I can see "mod_perl" on the "server" part of the http responses), I tryed this:

#!/usr/bin/perl print "Content type: text/html\n\n"; $username = $r->connection->user; my($ret, $password) = $r->get_basic_auth_pw; print $password;
And I get an "Internal Server Error". Do I have to use some library or something on the script?

Thanks!

Replies are listed 'Best First'.
RE: RE: RE: Getting username and password from the URL.
by btrott (Parson) on Jun 12, 2000 at 06:37 UTC
    Yes, you'll need to get the $r object, which you don't have in your script. $r is the Apache request record.

    You should set up your script as an Apache::Registry script. Then you can get $r like this:

    my $r = Apache->request;
    To set the script up as Apache::Registry, add something like this to httpd.conf:
    <Location /perl> SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI </Location>
    This sets up the perl subroutine under the document root to run under Apache::Registry. So put your script there.

    Or, if you set up a mod_perl handler, your handler subroutine will be passed $r.

    For example, you might set up a handler thusly in your httpd.conf:

    <Location /foo> SetHandler perl-script PerlHandler My::Foo </Location>
    And then in My::Foo:
    package My::Foo; use strict; sub handler { my $r = shift; my $user = $r->connection->user; my($ret, $password) = $r->get_basic_auth_pw; $r->send_http_header; $r->print($user); $r->print($password); } 1;
    I'd recommend trying the first approach.
RE: RE: RE: Getting username and password from the URL.
by jjhorner (Hermit) on Jun 12, 2000 at 06:50 UTC

    While btrott's answer was right, I thought I would send you to a real world example here.

    J. J. Horner
    Linux, Perl, Apache, Stronghold, Unix
    jhorner@knoxlug.org http://www.knoxlug.org/
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://17658]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found