in reply to Integrating Script with .htaccess
package MyAuth; sub Authorize { $ENV{HTTP_AUTHORIZATION}=~/^Basic (.*)/i ){ my $up = $1 || ''; my ($user,$pass)=split(/:/,BASE64_DECODE( $up ),2); if( db_query($user,$pass) ){ $ENV{REMOTE_USER} = $user; return "success"; }else{ print "Status: 401 Authorization Failed\r\n"; print "WWW-Authenticate: Basic realm=\"whatever\"\r\n"; print "Content-type: text/html\r\n\r\n"; print "Content to be displayed on a canceled login."; exit; } }
Then in your cgi put the following...
#!/usr/bin/perl use MyAuth; MyAuth::Authorize; # below this line I am authorized # do whatever else
You can even write a hybrid that does cookies if they have them, and htauth if they don't (we have a hybrid system that does just that).
my @a=qw(random brilliant braindead); print $a[rand(@a)];
|
|---|