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

Hello, I'm looking for a little assistance on a script that I've been working on. I'm trying to figure out how to check if values are being passed from one script to another...and if the values are not passed properly give an error to the user. Here's the snip:
use CGI; my $q = new CGI; $user_id=$q->param('userid'); $user_email=$q->param('useremail'); $user_name=$q->param('username'); $give_access = "<a href=give_access.cgi?setsig;user=$user_id;email=$us +er_email;passwd=$user_password;multiname=$multiname>";
I want to give an error message if the user tries to access the program directly "give_access.cgi", without using a standard form that would provide the userid, useremail, and username. I've tried the following but keep getting a error-500:
if ($q->param('userid')) { } else { &error_message("You need to use the form to access this progr +am!"); } sub error_message { local($e) = @_; print <<"END"; <html> <head> <title>Error</title> <center> Error. The error seems to be:<p> $e END exit; }
Any suggestions? Thanks! Lis.

Replies are listed 'Best First'.
Re: Value Check
by blaze (Friar) on May 30, 2003 at 23:32 UTC
    you could always just do:

    if($q->param('userid') eq ""){

    or

    if(! $q->param('userid')){

    though you realize that all someone has to do to bypass this is add a query string right? you may be better off just making sure it's coming from your form specifically using $ENV{'HTTP_REFERER'}, which still isnt foolproof

    -Robert

    Hopefully there will be a witty sig here at some point
      That did the trick! Thank You!!
      if(! $q->param('userid'))
      Have a great weekend! Lis.
Re: Value Check
by tcf22 (Priest) on May 30, 2003 at 23:49 UTC
    I definitely think using
    if(! $q->param('userid'))
    is a good idea.

    I think you may be getting an error because you aren't specifying a Content-type.
    Try putting one of these at the top of your script.
    print "Content-type: text/html\n\n";
    or
    print $q->header;