/    Sign up×
Community /Pin to ProfileBookmark

Can my Perl script see which .htaccess "user" is accessing it?

Greetings,

I have password-protected a directory, via .htaccess. (Actually my provider’s control panel did that part behind the scenes.) Once a person has typed in their username and password to access the protected directory, the index.html page calls a Perl script which needs to know who is using it.

Is there any way the Perl script can see which .htaccess “user” requested the page that called it? Otherwise, I have to make the person log in twice: once to get into the directory, and another via log-in code I have to include in the script.

In my server logs, when there is a page request for a page that lives in a protected directory, it shows the “user” name in the output. But when I do a dump of $ENV variables using this code in a test script (called by a form on a page in the protected directory):

foreach (sort keys %ENV) {
print “$_ = $ENV{$_}nn”;
}

the name of the user (in this case, me) is not in any of the variables. Is this because the script itself lives in cgi-bin, and not the password-protected directory?

Is there any way I can make the protected-directory log-in procedure do double duty?

Thanks!
DM

to post a comment

2 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottApr 03.2007 — Is there any way the Perl script can see which .htaccess "user" requested the page that called it?[/quote]Yes. It will be available in [font=courier]$ENV{REMOTE_USER}[/font].

the name of the user (in this case, me) is not in any of the variables. Is this because the script itself lives in cgi-bin, and not the password-protected directory?[/quote]That's exactly right. So you will need to either password protect a directory within the cgi-bin or make a CGI-enabled directory within your protected directory.
Copy linkTweet thisAlerts:
@doctormelodiousauthorApr 03.2007 — Thanks for the reply Jeff!

DM
×

Success!

Help @doctormelodious spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...