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

I have a script directory path on my unix server:
http://hostname.com/work-bin/directory/mailScript.cgi
I use this for my form action part in my HTML page to call the Perl script and the mail script works.

Sometimes I need to send this URL out to people and they mistakenly click on the above link it executes the mail script. I was wondering how I can stop the mail script executing if users click on the link. I assume I need to put some condition at top of my script:
if ($field not defined) { print "Mail script only, not for browser viewing\n"; }
I am not sure so was hoping someone could help me with this?

Replies are listed 'Best First'.
Re: Mail url executes
by bart (Canon) on Sep 23, 2003 at 18:55 UTC
    You can require the presence of certain form parameters, and even for an exact magic value for a particular parameter, which you can set as a hidden input value in your form. The script should reject sending any mail if this condition isn't met.

    It can't stop the script from being executed, but it can be used to make it to refuse to actually do anything.

    The code can look something like (untested, it's just an idea for a starting point):

    unless(param('magicvalue') && param('magicvalue') eq 'magicpassword') print header(-status => 403), print "<html>Mail script only, not for browser viewing</html>"; exit; }
Re: Mail url executes
by PodMaster (Abbot) on Sep 23, 2003 at 18:53 UTC
    Simply redirect the people to your HTML page.
    unless(defined $field){ require CGI; print CGI->redirect("/my/html/page/whatever"); }

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.