Question

I am trying to setup a login page to be used with awstats, so that the content is only viewable by authenticated users.

Ideally, I would like to create my own login page, and if a user is not logged in when the visit the stats page, they are redirected to the login page. (Right now there is no authentication)

The problem is that I don't know how to implement this. I have tried googling this, but the only solutions I could find were to use .htaccess (which I would rather not use in this case if I don't have to)

Has anyone implemented something similar to this?

Was it helpful?

Solution

.htaccess is the right tool for this job, but if you insist, the ancient ancient ancient way

#!/usr/bin/perl --
use strict;
use warnings;
use CGI;
Main( @ARGV );
exit( 0 );
sub  Main {
    my ( $q ) = CGI->new;
    if( $q->param('password') eq 'secret' ){
        print ShowAWSTATS($q);
    } else {
        print ShowLoginForm($q);
    }
}

where ShowLoginForm() prints a content header $q->header along with the html for a login form, and ShowAWSTATS prints a content header, and say, some html as provided by awstats.pl

Like Len Jaffe says, there is much much much more that needs to be done, so you want to use .htaccess (its either 3min with .htaccess or hours with anything else)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top