Reputation: 9212
I have few Perl scripts those gets execute even if we pass the URL in browser address bar. I just want to stop this behavior. What i want is when user clicks on button or link on which scripts are attached then only they should get execute.
www.example.com/cgi-bin/abc.cgi --- Should not work.
<button on-click="/cgi-bin/abc.cgi"> Execute me </button> -- it should work
How to do this?
Upvotes: 1
Views: 93
Reputation: 3153
You can do that, there are two ways to go about it. One, when buttons are clicked you can submit a form using the POST method, and the code should only be execute when the script is invoked using the POST method, e.g.:
HTML:
<form method="POST" action="/cgi-bin/abc.cgi"><input type="submit" name="submit_button" value="Execute me"><form>
Perl code:
if($ENV{REQUEST_METHOD} eq 'POST') {
## execute special code
}
Two, you can check for an parameter in the query string:
HTML:
<input type="button" value="Execute me" onClick="window.location.href='/cgi-bin/abc.cgi?doExecute=1';">
Perl:
use CGI;
my $cgi = new CGI;
if(defined $cgi->param('doExecute') && $cgi->param('doExecute')) {
## execute special code
}
I hope this helps.
Upvotes: 4