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

I have a script for an action page. Everything works great and the redirect does redirect if I try and click on the url of the action page. The problem with my redirect part is it wont redirect when I hit refresh or reload on my browswer. It seems to want to process the page again with each refresh of the page. Please advise how I can correct this?
my $subject = param('subject'); my $site = 'www.mysite.com'; my $webpage = new CGI; #redirect unless(defined($subject)) { print $webpage -> redirect($site); exit(0); }

Replies are listed 'Best First'.
Re: Redirect after refresh of page
by dragonchild (Archbishop) on May 24, 2004 at 13:15 UTC
    Don't redirect to the same script? Whenever I have an action page that is reload-unsafe, I redirect to a non-action page after taking the action. That way, the only pages that are reloadable are the initial form and the non-action page. The actual action is never reloadable because the browser never stops on it.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      I am redirecting to a non action page. Sorry if it was not clear but the redirect is suppose to go back to the form page.
        Then, you're carrying around variables that are making your form reload-unsafe. *shrugs* Without seeing more of the code, there's not much more I can say.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re: Redirect after refresh of page
by Joost (Canon) on May 24, 2004 at 18:43 UTC
    It won't redirect when you reload which page?

    Do you redirect when the form processing is done, or just when you don't have enough input? Keep in mind that reloading a submission generally resubmits the data (unless you redirect after processing it). That's why browsers issue warnings about resubmitting a POST request.

    Also:

    You'll need to redirect to 'http://www.mysite.com' instead of 'www.mysite.com';

    Should you be using a POST method or a GET method in your form submission?

    Please don't mix the object oriented CGI interface with the functional one, it hurts my eyes.

Re: Redirect after refresh of page
by eric256 (Parson) on May 24, 2004 at 15:23 UTC
    I'm not sure if this is your problem but you should include the http:// part otherwise it will not work.

    ___________
    Eric Hodges
Re: Redirect after refresh of page
by soon_j (Scribe) on May 24, 2004 at 12:56 UTC
    I don't know it this helps, but try to see in your browser's perference if the cache is set to be updated every time you view the page and not only when the page is outdated.