.htaccess from perl script?

M

Mark

Hi,

I am trying to send a username and password from a perl script in
order to access documents in a directory secured by a .htaccess file.
I am using the location command to send the access details as part of
the url as follows;

print "Location:
http://username:password\@www.mysite.com/docs/show.htm\n\n";

The result is that the password box shows in the browser with the
username and password entered correctly but the user has to click ok
to access the documents.

I would much prefer the password box not to appear at all. If I enter
the url into the browser address window access is gained without the
password window showing.

Is there something I can add to the script to overcome this problem?

Many thanks,
Mark
 
W

Walter Roberson

:I am trying to send a username and password from a perl script in
:eek:rder to access documents in a directory secured by a .htaccess file.
:I am using the location command to send the access details as part of
:the url as follows;

:print "Location:
:http://username:password\@www.mysite.com/docs/show.htm\n\n";

:The result is that the password box shows in the browser with the
:username and password entered correctly but the user has to click ok
:to access the documents.

You should be sending the credentials as part of the HTTP/1.1
headers. See the http standards on how to send the credentials,
or just sniff a session and read off the headers sent.
 
G

Gregory Toomey

It was a dark and stormy night, and Mark managed to scribble:
Hi,

I am trying to send a username and password from a perl script in
order to access documents in a directory secured by a .htaccess file.
I am using the location command to send the access details as part of
the url as follows;

print "Location:
http://username:password\@www.mysite.com/docs/show.htm\n\n";

The result is that the password box shows in the browser with the
username and password entered correctly but the user has to click ok
to access the documents.

I would much prefer the password box not to appear at all. If I enter
the url into the browser address window access is gained without the
password window showing.

Is there something I can add to the script to overcome this problem?

Many thanks,
Mark

I'm not sure what you're doing, but I use LPW:Simple, get() and userids/passwords all the time.
Note that passwords usually secure the whole site, so you may need to pass userid/password everytime you use get().

eg

#!/usr/bin/perl
use LWP::Simple;
use strict;

my $result=get("http://username:password\@www.mysite.com/docs/show.htm");


gtoomey
 
S

Sisyphus

Gregory said:
eg

#!/usr/bin/perl
use LWP::Simple;
use strict;

my $result=get("http://username:password\@www.mysite.com/docs/show.htm");

Just curious - what do you do if the password contains an "@" symbol.
Let's say the username is 'username' and the password is 'p@ssword':
my $result=get("http://username:p\@ssword\@www.mysite.com/docs/show.htm");

For me that would typically result in an error about not being able to
find '(e-mail address removed)'.

I couldn't work out a solution.

Cheers,
Rob
 
R

Randal L. Schwartz

Sisyphus> Just curious - what do you do if the password contains an "@"
Sisyphus> symbol. Let's say the username is 'username' and the password is
Sisyphus> 'p@ssword':
Sisyphus> my $result=get("http://username:p\@ssword\@www.mysite.com/docs/show.htm");

Sisyphus> For me that would typically result in an error about not being able to
Sisyphus> find '(e-mail address removed)'.

You URI-encode it. As always. @ is %40, unless i'm not awake yet.

print "Just another Perl hacker,"
 
E

Eric Schwartz

Sisyphus> Just curious - what do you do if the password contains an "@"
Sisyphus> symbol. Let's say the username is 'username' and the password is
Sisyphus> 'p@ssword':
Sisyphus> my $result=get("http://username:p\@ssword\@www.mysite.com/docs/show.htm");

Sisyphus> For me that would typically result in an error about not being able to
Sisyphus> find '(e-mail address removed)'.

You URI-encode it. As always. @ is %40, unless i'm not awake yet.

Or you're a lazy bastard and use URI::Escape. :)

$ perl -MURI::Escape -e 'print uri_escape("@"), "\n"'
%40

-=Eric
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top