3 PLP::HowTo - Some examples of commong web things in PLP.
7 Additional Perl functionality is often available in modules. All of the modules
8 used in this document are available (for free) at CPAN: http://search.cpan.org/
28 Your user ID is <:= $cookie{ID} :>
34 $header{Content_Type} = 'text/plain';
40 Use DBI, and alternatively, one of the many simplifying modules. Drivers for
41 DBI are in the DBD:: namespace. DBI loads the driver automatically, but it has
42 to be available. If you need a fast full-featured file-base database, use
43 DBD::SQLite, it's the instant database :).
46 use DBIx::Simple; # and read its documentation for examples.
49 =head2 allow a user to upload a file
51 Use CGI.pm, which can be used with CGI::Upload to make things easier
54 use CGI; # and don't use %post in your PLP document.
55 use CGI::Upload; # and read its documentation for examples.
57 my $upload = CGI::Upload->new($cgi);
61 =head2 download a file into a variable
65 my $page = get 'http://foo.com/bar.html';
68 =head2 implement basic authentication
70 This only works with PLP under mod_perl. For CGI installations, it's useless.
76 my $r = Apache->request;
78 my ($type, $login) = split / /, $r->header_in('Authorization');
79 my ($user, $pass) = split /:/, decode_base64 $login, 2;
81 unless ($user eq 'foo' and $pass eq 'bar') {
82 $header{Status} = '401 Authorization Required';
83 $header{WWW_Authenticate} = 'Basic realm="Top secret :)"';
84 print '<h1>Authorization Required</h1>';
90 (It is possible to use something similar with CGI, but it's not easy. Headers
91 are communicated to your script via C<%ENV>, and having credentials in there
92 would be insecure, so Apache removes them. To get C<$ENV{HTTP_AUTHORIZATION}>,
93 you need to recompile Apache with -DSECURITY_HOLE_PASS_AUTHORIZATION, or use
94 mod_rewrite to set the environment variable. Short answer: just use mod_perl.)
98 If you have good, simple examples of how to do common things with PLP, please
99 send them! <perl@shiar.org>