Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
pass username/password from a script into http basic authentication
Old 04-21-2008, 12:23 AM pass username/password from a script into http basic authentication
Novice Talker

Posts: 14
Name: Anon Hanon
Trades: 0
I am protecting a series of pdf files with http basic authenication using a htaccess file. Currently I have users click a link that links to a perl script in a password protected directory. This forces them to login and then the perl script redirects them to the correct pdf file based on their username. All of the pdf files are username.pdf.

What I really want is them to type in their username and password into a html form and this form to pass the values to some script that could redirect them and send username and password data to htaccess so that they are automatically authenicated. Is this possible?

I know how to write a perl script to redirect them based off a html form inputted username but I do not know how to pass the values to http authentication.

Thanks.

Last edited by PleaseDontBugMe; 04-21-2008 at 12:25 AM.. Reason: clarify that I know how to redirect based on the username
PleaseDontBugMe is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-23-2008, 11:39 AM Re: pass username/password from a script into http basic authentication
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
just a thought but, why not have the perl script just write the file back to the user (avoid the whole htaccess bit altogether)

OTOH, if you do want to continue down this path....
have the perl 302 redirect send them to the htaccess controlled file like this:
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 04-26-2008, 04:06 PM Re: pass username/password from a script into http basic authentication
Ultra Talker

Posts: 407
Trades: 1
How about this:

Code:
RewriteRule (.*\.pdf)$ auth.cgi?pdf=$1
Then auth.cgi would check to see if the user is logged in, and if so, it would send the PDF headers and output the document.
__________________
[
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
]
Lucas3677 is offline
Reply With Quote
View Public Profile Visit Lucas3677's homepage!
 
Old 04-29-2008, 10:44 AM Re: pass username/password from a script into http basic authentication
addonchat's Avatar
Super Talker

Posts: 115
Name: Chris Duerr
Trades: 0
Quote:
Originally Posted by willcode4beer View Post
just a thought but, why not have the perl script just write the file back to the user (avoid the whole htaccess bit altogether)
+1

Put the PDF files in an unaccessible directory, then just spit the file out:
Code:
#!/usr/bin/perl

print "Content-type: application/pdf\n\n";
open(FILE, "somefile.pdf") or die ("Cannot open file");
@data = <FILE>;
close(FILE);
foreach $line (@data) { print $line; }
__________________
Chris Duerr
AddonChat Java Chat Software

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
addonchat is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 11:47 AM Re: pass username/password from a script into http basic authentication
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Whoohoo, hey, look at that !
Comprehensible Perl code !

A true wonder of the world...
Tried to add TP, but could not. I have to "spread some more" before, but I needed to say that
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-29-2008, 12:01 PM Re: pass username/password from a script into http basic authentication
addonchat's Avatar
Super Talker

Posts: 115
Name: Chris Duerr
Trades: 0
lol I try.
__________________
Chris Duerr
AddonChat Java Chat Software

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
addonchat is offline
Reply With Quote
View Public Profile
 
Old 04-30-2008, 11:36 PM Re: pass username/password from a script into http basic authentication
Novice Talker

Posts: 14
Name: Anon Hanon
Trades: 0
Is there anyway to do something similar in PHP?
PleaseDontBugMe is offline
Reply With Quote
View Public Profile
 
Old 05-01-2008, 12:15 AM Re: pass username/password from a script into http basic authentication
addonchat's Avatar
Super Talker

Posts: 115
Name: Chris Duerr
Trades: 0
PHP Code:
<?php

   header
("Content-type: application/pdf");   
   echo 
file_get_contents("somefile.pdf");

?>
__________________
Chris Duerr
AddonChat Java Chat Software

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
addonchat is offline
Reply With Quote
View Public Profile
 
Old 05-01-2008, 01:38 AM Re: pass username/password from a script into http basic authentication
Novice Talker

Posts: 14
Name: Anon Hanon
Trades: 0
Thank you to all of you. I cannot thank you enough. I have searched the web and have not found a solution until you guys answered my question.
PleaseDontBugMe is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to pass username/password from a script into http basic authentication
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.62358 seconds with 12 queries