Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.pl cgi scripts executes multiple times ?? 1

Status
Not open for further replies.

Arainxius

Technical User
Sep 11, 2003
16
0
0
CA
Hi:

I am new to PERL-CGI programming.
i have a simple CGI application.
There is a form localhost/form.html which invokes the run.pl script at localhost/cgi-bin/run.pl

This perl-cgi scripts parses the form paramters and executess an application. and displays the message that produced results are available at localhost/result.htm
The user clicks on this URL and goes through the results.

Now when i click the back button on the browser IE6. It gives following message

Warning: Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you.

To resubmit your information and view this Web page, click the Refresh button

At this moment the the address field of the IE6 is showing localhost/cgi-bin/run.pl. when i click the "refresh". It again automatically behind the scence sends the previously submitted form paraters to the run.pl cgi script and that again runs the application and produces the results again.

I want to disable this second and subsequent execution of the run.pl cgi scrip. The run.pl should only execute when the user clicks the submit button on the form rather than 'reload' on the IE6.

Any help

thanks

Arainxius
 
This is default behaviour, and what should be expected.

What you could do is generate a page, and redirect to that, to get around this issue.

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Hi Paul:

generate a page and redirect to that ?

Does it means !! that the run.pl writes to a file such as result.html rather than outputin directly using print statements.
Once the result.html file is generated then redirect to that page !!

If so then where this redirect part will be implemented ? and how to redirect it ?

thanks

Arainxius
 
The redirect can be handled in many ways, look up redirect in CGI.pm

You could also use the meta tags to redirect
print "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=Http://mysite.com/results.htm\">";

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Thanks Paul:

I have redirected to the results.htm. In my .pl script file I am executing an external application e.g
system("clustalw.exe $alignment ");
Now I am redirected to the results.htm page when the clustalw.exe application returns. It takes around 8-10 minutes depending upton the arguments to execute it. And during this time the webbrowser still shows run.pl in the URL address and if i reload the page then run.pl is again executed and its like drawing money from your account twice.


any suggestions..

thanks

arainxius

 
This could be a bit messy

but simple semaphores might do it

Instead of just running the process, check for the existence of a file, if it doesn't exist, create it, and then run the process, on successful completion delete the file

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Paul:

Thats good idea...
but i guess there is problem with that... as i generate the name of the result.htm randomly such as result_timestamp.htm so that the output of client request is stored in a specific file.

So when the run.pl script is invoked by clicking "reload" on the IE it doesn't know the know before hand what was the name of the previous result.htm file. !! !!

the real problem is that run.pl somehow needs to ignore the request if it has been invoked by 'reload' of IE...

thanks

arainxius
 
lets call the file say
20040712203615.lock
todays date, and the time in HHMMSS

And then in your script check for a file that is younger than ten minutes (arbitrary based on 10 mins to complete)
Code:
opendir DIR "/path/to/files";
@files=readdir DIR;
closedir DIR;
foreach (@files) {
  ($filename,$ext)=split(/\./, $_);
  $ok_to_proceed=1;
  if ($ext eq "lock") {
    #check if file is younger than 10 mins
    #$ok_to_proceed = -1 if test fails
  }
}
if ($ok_to_proceed == 1) {
#  create file
#  run your program
#  delete file
}

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Paul:

Thats really good idea..
there is one drawback .. that at one time only one client can be serviced...

thanks

arainxius
 
OK, lets include the IP address of the client into the file name

HTH
--Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Hi Paul:

I am following the approach that you mentioned..thanks...
There is one issue. If the client is on the local network NAT then the client IP address will be of gateway. That will limit the service to only one client in one local network..

again thanks for your help..

Arainxius
 
OK, so lets include $ENV{'REMOTE_HOST'} into the file name, and that should get around that, it's just that the file name is starting to look ridiculous.

Might be an idea to store this information in a database, and then just query the database

[remote user]|[machine name]|[ip address]|[start date & time]|[end date & time] - not all environment variables can be guaranteed.

From point of view of maintentance, rather than having to housekeep a shed load of text files

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top