Nik has asked for the wisdom of the Perl Monks concerning the following question:

When a user hits on a link of my webpage(the fun ballob button) i want the user redirected to games.pl script but i want him to enter some credentials first username and pass. I have made the follwoing script inside games.pl but unfortunatealy i cant even see the htttp auth login dialog window. Anyone can see why?
my $browser = LWP::UserAgent->new; $browser->credentials( 'www.nikolas.tk:80', 'Personal Folder', 'nikos' => '********' ); my $url = 'http://www.nikolas.tk/cgi-bin/games.pl'; my $response = $browser->get($url); die "Error: ", $response->header('Nikos Personal Folder') || 'Error ac +cessing', "\n ", $response->status_line, "\n at $url\n Aborting" unless $response->is_success;
I have also created the .htacess and .htpasswd files but iam consused here. do ireally need to sue them?

Replies are listed 'Best First'.
Re: http authentication dialog
by kgraff (Monk) on May 24, 2005 at 19:04 UTC

    Before you start coding, consider how you want the site to work. If you want to authenticate from a database, for instance so that users can pick their their own user ID and change passwords you will need to do some coding.

    Using .htaccess and .htpasswd files should work without doing any separate coding IF you are willing to edit them yourself. Just make sure that the script is in a directory or a directory underneath the one containing .htaccess and that your web host will handle .htaccess files. Some hosts restrict where you can store script files as well.

Re: http authentication dialog
by brian_d_foy (Abbot) on May 24, 2005 at 21:06 UTC

    You won't get an dialog unless you create it yourself: that's wholly a function of the user-agent.

    Since you are setting the credentials before you make the request, you should already be passing an Authorization header. When the webserver sees the Authorization header, and that header has valid credentials, it doesn't need to challenge you, so it does not need to return a 401 status. It simply allows access to the resource. You get to skip that step in your program because you already know to pass the info.

    Ensure that you're using the right realm in credentials, and turn on debugging (or use an HTTP sniffer) to look at the actual request. Check the access log of the web server to see what it did (such as returning a 403 Forbidden response).

    If you want us to figure out what's going on with your script, you should give us the output as well as the code. Some of my advice in Troubleshooting Perl CGI scripts applies here.

    Good luck. :)

    --
    brian d foy <brian@stonehenge.com>
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: http authentication dialog
by snookmz (Beadle) on May 24, 2005 at 20:56 UTC
    "do ireally need to sue them?"

    It's the American way! :)