- <:
- use CGI; # and don't use %post in your PLP document.
- use CGI::Upload; # and read its documentation for examples.
- my $cgi = CGI->new;
- my $upload = CGI::Upload->new($cgi);
- ...
- :>
-=item download a file into a variable
+ <:
+ use CGI; # and don't use %post in your PLP document.
+ use CGI::Upload; # and read its documentation for examples.
+ my $cgi = CGI->new;
+ my $upload = CGI::Upload->new($cgi);
+ ...
+ :>
+
+=head2 download a file into a variable
+
+ <:
+ use LWP::Simple;
+ my $page = get 'http://foo.com/bar.html';
+ :>
+
+=head2 implement basic authentication
+
+This only works with PLP under mod_perl. For CGI installations, it's useless.
+
+ <:
+ use MIME::Base64;
+
+ BEGIN {
+ my $r = Apache->request;
+
+ my ($type, $login) = split / /, $r->header_in('Authorization');
+ my ($user, $pass) = split /:/, decode_base64 $login, 2;
+
+ unless ($user eq 'foo' and $pass eq 'bar') {
+ $header{Status} = '401 Authorization Required';
+ $header{WWW_Authenticate} = 'Basic realm="Top secret :)"';
+ print '<h1>Authorization Required</h1>';
+ exit;
+ }
+ }
+ :>