Re: Headers, downloads and redirection

From: Fabian Hore (fabianhore_at_email.com)
Date: 11/08/04


Date: Mon, 08 Nov 2004 01:08:32 GMT

Hi.

> > I have a script which validates a user's email, password and IP for
> > the purposes of a file download. The validation and error messages
> > work perfectly. After the validation and download, I want to redirect
> > the user to a thank you page.

I don't see how you can send a document and a redirect in the same stream.
If you send a document with a Location header the browser should ignore the
body
of that document and instead send another request for the specified
location.

If this works on some browsers, or on some sites, then I'd take that as a
fluke not to
be relied upon.
I guess the method could succeed if the body of the original document is
received
quickly enough before the subsequent one starts to download.
Best to steer clear of anything that goes against the way the protocol is
supposed to behave.

I just ran a quick test;
  <?php
  header("Content-Disposition: attachment; filename=doc.doc");
  header("Content-Type: application/octet-stream");
  header("Location: ./thanks.php");
  echo readfile('./doc.doc');
  ?>

I never get the document.. just the thanks page. This is what I'd expect.
You say you get the download but not the redirect, which is odd!
I'd put it down to browser nuances and use a more reliable method.

I would suggest sending back the thanks page first which provides a link
and/or Javascript
invocation of the download. This will of course mean maintaining the state
of validation on
the server between requests.

"Ilija Studen" <remove_this_ilija.studen@gmail.com> wrote in message
news:2v79trF2jnlreU1@uni-berlin.de...
> Tyrone Slothrop wrote:
> > I have a script which validates a user's email, password and IP for
> > the purposes of a file download. The validation and error messages
> > work perfectly. After the validation and download, I want to redirect
> > the user to a thank you page. I have done this on other sites with no
> > problems, but this one seems to have a difference that is making me
> > crazy.
> >
> > The download works fine with the usual cache headers and force
> > download, readfile etc. However, the script refuses to redirect. I
> > have tried header ("location: ...") and an abbreviated echo of an HTML
> > redirect and neither works. Thought maybe it was a cache problem, so
> > I tried ob_start and ob_flush (worked great for the redirect, but the
> > file would not download).
> >
> > Anyone have any ideas?
> >
> > TIA!
>
> Try to print:
>
> <head>
> <script language="JavaScript">
> <!--
> window.location="http://someplace.com";
> //-->
> </script>
> </head>
>
> If server wonnt redirect, you can hope that browser will.



Relevant Pages

  • Headers, downloads and redirection
    ... the purposes of a file download. ... After the validation and download, ... the script refuses to redirect. ...
    (alt.php)
  • Re: php redirection question
    ... >> function attempts to force the download of the pic, ... > browser is displaying at all. ... Sorry if I'm missing the point but I've just seen this thread. ... sticking a redirect in a page on it's own and then calling it through the ...
    (uk.net.web.authoring)
  • Re: Headers, downloads and redirection
    ... After the validation and download, ... the script refuses to redirect. ...
    (alt.php)
  • Re: WebClient - detect response redirect
    ... there is the AllowAutoRedirect property ... > I'm writing a console utility to download specific files from web sites ... > certain sites where the admin has set up a redirect to handle the 404 ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Newbie question about configuration.
    ... how to redirect to a website. ... I have also denied access to certain files from being downloaded. ... banned sites but can I do the same if someone tries to download a file ... go into the Rule that denies the website. ...
    (microsoft.public.isaserver)