Perl And Apache.

M

Morris.C

A quick Perl (or it could be Apache!) question:

After UserID/Password authentication on a web page, does Apache store the
UserID in an environment variable that a Perl script could use?

I've used a Perl script called 'test-cgi', but the UserID that it always
returns is "apache".

Any help would be appreciated.

Thanks.
 
I

it_says_BALLS_on_your_forehead

Morris.C said:
A quick Perl (or it could be Apache!) question:

After UserID/Password authentication on a web page, does Apache store the
UserID in an environment variable that a Perl script could use?

I've used a Perl script called 'test-cgi', but the UserID that it always
returns is "apache".

Any help would be appreciated.

Thanks.

if you are using the CGI module, you have access to any html form
values that you submitted through POST, or that you entered in the
query string.

so if on one page, you had a link (or form action to) /cgi-bin/page2.pl

in page2.pl, you could have:

#!/usr/bin/perl

use strict; use warnings;
use CGI;

my $user = param('user');

print "Content-type: text/html\n\n";
print "$user<br>\n";


....if on the first page you had:
<input type=text name=username id=username value="">

something like that. the id is optional, but CGI requires that the html
tag have a name attribute.
 
I

it_says_BALLS_on_your_forehead

it_says_BALLS_on_your_forehead said:
if you are using the CGI module, you have access to any html form
values that you submitted through POST, or that you entered in the
query string.

so if on one page, you had a link (or form action to) /cgi-bin/page2.pl

in page2.pl, you could have:

#!/usr/bin/perl

use strict; use warnings;
use CGI;

my $user = param('user');

....sorry, that should be:
my $user = param('username');

in this example
 
I

it_says_BALLS_on_your_forehead

John said:
I never understood this horrible syntax, what's wrong with:

use CGI ':standard';

why is it that for some modules you only need:
use <module>;

....but others you need to specify certain functions or sets of
functions?
 
M

Matt Garrish

it_says_BALLS_on_your_forehead said:
why is it that for some modules you only need:
use <module>;

...but others you need to specify certain functions or sets of
functions?

I don't know if you're joking, but it's because not every module is going to
pollute your namespace by default. If the module doesn't export the
functions you want to use automatically, you have to ask for them.

You could also create an object and use it instead:

useCGI;
my $q = new CGI;
my $username = $q->param('username');

Matt
 
M

Matt Garrish

Matt Garrish said:
I don't know if you're joking, but it's because not every module is going
to pollute your namespace by default. If the module doesn't export the
functions you want to use automatically, you have to ask for them.

You could also create an object and use it instead:

useCGI;

without the typo, of course...
my $q = new CGI;
my $username = $q->param('username');

Matt
 
I

it_says_BALLS_on_your_forehead

Matt said:
without the typo, of course...

hehe, no prob. i produce typos like it's my job :).

and no, i wasn't joking--learn something new every day. thanks Matt.
 
J

John Bokma

Matt Garrish said:
useCGI;
my $q = new CGI;
my $username = $q->param('username');

I also never understood why people prefer to call it $q(uery) :-D

I use my $cgi = new CGI; since I consider things like $query->header();
extremely confusing.
 
B

Brian Wakem

John said:
I also never understood why people prefer to call it $q(uery) :-D

I use my $cgi = new CGI; since I consider things like $query->header();
extremely confusing.


I think this comes down to books. The first Perl/CGI book I read use $query
for all CGI stuff and I've used it ever since.
 
M

Matt Garrish

Brian Wakem said:
I think this comes down to books. The first Perl/CGI book I read use
$query
for all CGI stuff and I've used it ever since.

Documentation for me. If I use a module I try to stick to the conventions
used by the author of the module (as much as that is possible, anyway) so
that whoever has to maintain the code after me can quickly see the
relationship. This way if that poor unfortunate soul looks up a method and
sees $q->some_method() they don't have to go through the extra step of
checking that $q is the same thing as $cgi (although it's always a wise
step!).

Matt
 
J

John Bokma

Matt Garrish said:
Documentation for me. If I use a module I try to stick to the
conventions used by the author of the module (as much as that is
possible, anyway)

I agree with you, however, I consider this an exception. (In the past I
did use $query. However, after giving it some thought, I considered $cgi
much better).
so that whoever has to maintain the code after me
can quickly see the relationship. This way if that poor unfortunate
soul looks up a method and sees $q->some_method() they don't have to
go through the extra step of checking that $q is the same thing as
$cgi (although it's always a wise step!).

The documentation uses $q, $query, and the non OO way, so hmmm... (I
rarely use single letter variables btw).

And someone who has a problem with $cgi is not qualified to maintain
(my) code, as simple as that.
 
X

xhoster

John Bokma said:
I never understood this horrible syntax, what's wrong with:

use CGI ':standard';

It is easier to add other tags to the first than to the second.

Xho
 
J

John Bokma

It is easier to add other tags to the first than to the second.

Yup, but then I would use

use CGI qw( :standard other tags to add );

A related "complaint" is why people use stuff like:

$f =~ m#foo#;

or

$p =~ s#foo#bar#;

(with foo, bar not containing /, but even if they do, there are better
options compared to # or other horrors )
 
B

Bart Lateur

Morris.C said:
After UserID/Password authentication on a web page, does Apache store the
UserID in an environment variable that a Perl script could use?

Authentication how? There's a huge difference between the browser
supported authentication with the dialog box, typically based upon
..htaccess/.htpasswd, and something your people put together on a normal
webform.
I've used a Perl script called 'test-cgi', but the UserID that it always
returns is "apache".

That's not how it works. For the former, browser native authentication,
there is indeed some environment variable set with the user name, but
not with the password. Try printing out the contents of %ENV in a test
page.

For the latter, you're on your own. You'll have to use one of the
typical technologies to create and keep track of a so-called session,
using a session ID -- combined with some associated data on the server.

Typical ways to do this is in a cookie, clean and hasslefree, but the
user has to allow cookies from your site; a hidden form variable you
pass along in every form (troublesome: forget it once and your user
suddenly finds himself logged out), and putting it in the URL (Google
for PATH_INFO), but with the major disadvantage that bookmarks will hold
the session id.

Check the info on environment variables on this page:

<http://hoohoo.ncsa.uiuc.edu/cgi/env.html>

HTH,
Bart.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,206
Latest member
SybilSchil

Latest Threads

Top