in reply to Re: Need help with redirect
in thread Need help with redirect

That makes sense. I moved the print content type line and now I get a big "Object Moved This Document can be found here" message, still no redirect.

Replies are listed 'Best First'.
Re^3: Need help with redirect
by almut (Canon) on Jun 02, 2009 at 01:54 UTC

    I think what you're trying to do (using a HTTP redirection header with SSI) isn't going to work that way. I don't usually use SSI, but I think the additional magic in the handling of content vs. headers that would be required here simply isn't implemented with most web servers.

    Essentially, there are three ways to redirect:

    • HTTP redirect (what you're trying)
    • HTML <meta http-equiv="refresh" content="0;url=http://..." />
    • JavaScript

    You could try method 2, though, if you really need to embed the script's output into some HTML page via SSI.  Using <meta http-equiv="refresh" ...>, the redirect instruction becomes part of the HTML page, which you've already begun outputting, when the SSI instruction is being encountered.

      To use method two, he'd have to move the SSI below the TITLE element.

      <!DOCTYPE html ...> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>...</title> <!--#exec cgi="/ssi/checkcookie.pl"--> ... </head> ... </html>
      a meta refresh would not work. I am using the SSI to protect certain pages. This is the first time I have tried to password protect a member's section of my site. Using a meta refresh can be easly bypassedby hitting the escape key fast enough. Using the SSI as the frisst thing called should allow the redirect to happen before the protected content is loaded.
        a meta refresh would not work.

        You'd have to send out the real content only in case the cookie is ok. Otherwise, redirect. If the users stop the redirect, they'll just get nothing... no content and no login page.

        Using the SSI as the first thing called should allow the redirect to happen before the protected content is loaded.

        As I said, I'm no SSI expert, but some quick googling seems to confirm my understanding (that it shouldn't).  But maybe someone else knows the trick to make it work...

Re^3: Need help with redirect
by ikegami (Patriarch) on Jun 02, 2009 at 01:41 UTC

    Update: I didn't clue in that you were launching the script via SSI. In SSI includes, the header is apparently ignored (which makes sense cause you can't send multiple headers). See almut's reply instead.


    It works fine for me

    #!/usr/bin/perl -w use strict; use CGI q~:standard~; use DBI; use CGI::Cookie; use CGI::Carp q~fatalsToBrowser~; print redirect(-location => 'http://admin.ffinfo.com/');

    But I could see it failing if the script was fetched executed using POST instead of GET.

    If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

    You may want a 303.

    The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource.

    If you can't get it to work, execute the script from the prompt and show us what you get. You may also want to find out what the browser is receiving using a browser plugin or a packet sniffer.

      Right the code works when called by it's self. It is when I call it the script via SSI that it does not work. I added the -Status => 303 command and get the same error.
Re^3: Need help with redirect
by Anonymous Monk on Jun 02, 2009 at 01:33 UTC
    That is called a redirect -- you can configure browsers to ignore redirects