Home > Archive > PERL CGI Freelance > June 2004 > self-calling CGI script problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
self-calling CGI script problem
|
|
| Richard Cross 2004-04-13, 8:31 am |
| I have a fairly simple CGI script that puts up 'holding pages' on a website
at the push of a button. It is self calling, i.e. at the beginning of the
script, it checks to see if any parameters have been passed; if they have it
then runs the appropriate action.
The problem I have is that when I first load up the page, users can press
the web browser's refresh button as many times as they like without effect.
But as soon as they hit a button (and thus submitting a parameter), after
that if they hit the refresh button again, it will always re-submit the form
with whatever the last parameter was.
I realise this is by design of Internet browsers, but I was wondering if
there is a way that I can clear the last parameter passed somewhere in my
script, after I have run the intended action? I can't really trust users
not to hit the refresh button....
Hope the above description is clear enough... :-)
| |
| Vorxion 2004-04-14, 4:32 am |
| In article <c5gkgk$r0c$1@news8.svr.pol.co.uk>, Richard Cross wrote:
>I have a fairly simple CGI script that puts up 'holding pages' on a website
>at the push of a button. It is self calling, i.e. at the beginning of the
>script, it checks to see if any parameters have been passed; if they have it
>then runs the appropriate action.
Your definition of "self-callng" is puzzling. To me, "self-calling" means
that a program named "blip" calls itself recursively: blip -> blip
I have no idea what you're talking about in your context.
>The problem I have is that when I first load up the page, users can press
>the web browser's refresh button as many times as they like without effect.
>But as soon as they hit a button (and thus submitting a parameter), after
>that if they hit the refresh button again, it will always re-submit the form
>with whatever the last parameter was.
Are your users stupid enough to have caching turned on? What happens if
you have them change it so it reloads -every time-?
Further, in the results you send back, have you tried the Expires: header
to force a timeout of the page they got?
>I realise this is by design of Internet browsers, but I was wondering if
>there is a way that I can clear the last parameter passed somewhere in my
>script, after I have run the intended action? I can't really trust users
>not to hit the refresh button....
To my knowledge, there's no way to do it from CGI. However, you can
possibly manipulate the browser's history list with JavaScript. This is
hardly foolproof, as not everyone will have JS enabled.
Probably the best thing to do is maintain a cache that's specific to your
script, and key it in by IP#:
(tie to db file)
$cached_host{$ENV{'REMOTE_ADDR'}} = $ENV{'QUERY_STRING'};
When you run, check exists($cached_host{${'REMOTE_ADDR'}}), and if it does,
then check the value against what they submitted. If it matches, drop it
on the floor and take whatever alternative action you want.
Note, of course, that this will only work in specific for GET. If you're
using POST anywhere, you'd want to write an algorithm to manually store the
parameter values as an assembled string and compare against that. Just run
throught $q->params() and grab the value for each and join the values with
a null, then store that whole lot for your query.
>Hope the above description is clear enough... :-)
Clear as mud. My answer is the best I can do given the explanation.
--
Vorxion - Member of The Vortexa Elite
| |
| Mothra 2004-04-14, 7:31 am |
| "Vorxion" <vorxion@knockingshopofthemind.com> wrote in message
news:407ce282$1_1@news.iglou.com...
> In article <c5gkgk$r0c$1@news8.svr.pol.co.uk>, Richard Cross wrote:
website[color=darkred]
the[color=darkred]
it[color=darkred]
>
> Your definition of "self-callng" is puzzling. To me, "self-calling" means
> that a program named "blip" calls itself recursively: blip -> blip
>
> I have no idea what you're talking about in your context.
>
Sorry - what I mean is that rather than using say
print $q->start_form(-action=>'./results.cgi');
I simply use
print $q->start_form();
which means that the CGI script posts back to itself with any parameters
that are passed, meaning that all your code can live in one file. Every
time this single file is run, it checked to see if it has been passed any
parameters.
effect.[color=darkred]
form[color=darkred]
>
> Are your users stupid enough to have caching turned on? What happens if
> you have them change it so it reloads -every time-?
>
Ah, c'mon now, users=stupid... it's up to me to try and make my program
foolproof ;-)
I actually managed to solve the problem another way, by making the form
action another page that ran some perl, then printed the following html that
redirects back to the main page again.
print
$q->start_html(-head=>meta({-http_equiv=>'Refresh', -content=>'0;URL=http:
//<server_ip>/cgi-bin/myscript.cgi'}));
But it's not great, as my users have to wait a couple of seconds for the
original page to redisplay.
| |
| Art Sackett 2004-06-09, 3:56 am |
| Richard Cross <mothra@mothra.pub> wrote:
> The problem I have is that when I first load up the page, users can press
> the web browser's refresh button as many times as they like without effect.
> But as soon as they hit a button (and thus submitting a parameter), after
> that if they hit the refresh button again, it will always re-submit the form
> with whatever the last parameter was.
Session ID's may be an option worth considering.
Tracking IP addresses as Vorxion suggested might work, but if your site
is on the internet, it will appear to fail mysteriously from time to
time. Users of such atrocities as AOL will appear to be coming from
many different IP addresses during one session, so cannot be reliably
identified by IP address.
--
Art Sackett,
Patron Saint of Drunken Fornication
| |
| Malcolm Dew-Jones 2004-06-09, 3:56 am |
| : Richard Cross <mothra@mothra.pub> (apparenttly) wrote:
: > The problem I have is that when I first load up the page, users can press
: > the web browser's refresh button as many times as they like without effect.
: > But as soon as they hit a button (and thus submitting a parameter), after
: > that if they hit the refresh button again, it will always re-submit the form
: > with whatever the last parameter was.
If the form uses the "post" method then refreshing the form will require
it to be resubmitted. If the form uses the "get" method, then the url
changes to include the parameter, and after that, the refresh will work
the same as it did originally.
If you wish to use the get method without changing the url (and without it
showing the parameters) then you can put the form data into a cookie using
javascript. That is not necessrily good, but is a possible technique,
which is why I mention it.
--
(Paying) telecommute programming projects wanted. Simply reply to this.
|
|
|
|
|