Can you redirect a page AFTER you force a PDF download (Using a PHP script)?

by Thomas
2 replies
  • WEB DESIGN
  • |
Hello Warriors:

I have a website where I offer a free PDF download without requiring an opt-in. You just click on the download button and, instead of just letting the PDF open in your browser, I'm using the following PHP code to "force" you to see the "Save As..." dialog box instead:

PHP Code:
<?php
header
('Content-disposition: attachment; filename=the-sticky-note-report.pdf');
header('Content-type: application/pdf');
readfile('the-sticky-note-report.pdf');
It works just fine, however, even though I have no opt-in, I'd still like to display a thank you page anyway. I tried adding the following PHP code to the same script:

PHP Code:
$URL="http://www.thestickynotereport.com/thank-you.html";
header ("Location: $URL"); 
If I put it in the script BEFORE the PDF-related code above, the script just redirects to the thank you page, but doesn't force the download. If it put it after, the PDF downloads, but the page won't redirect.

To be honest, my knowledge of PHP is limited mostly to monkey see-monkey do, so maybe it isn't even possible to force the download AND redirect the page as well...or is it? Does anyone know (and, if so, how is it done?)

(If you need to see the page in action, it's the first link in my sig.)

Thanks for any help or ideas!

Regards,
Tommy.
#download #force #page #pdf #php #redirect #script
  • Profile picture of the author 723Media
    Hey Thomas,

    Unfortunately you cant do that with headers. You may know but when you send the headers to the page, your essentially telling the browser that this is a new page request.

    You can't set a series of header commands. Your browser can only handle a set amount of headers.

    How do people get to this page?
    {{ DiscussionBoard.errors[2655051].message }}
    • Profile picture of the author Thomas
      Originally Posted by 723Media View Post

      Unfortunately you cant do that with headers. You may know but when you send the headers to the page, your essentially telling the browser that this is a new page request.

      You can't set a series of header commands. Your browser can only handle a set amount of headers.
      I thought as much. Aw...

      Originally Posted by 723Media View Post

      How do people get to this page?
      At the moment, from nowhere other than my sig. In the future, it's very likely to be virtually all via direct linking. I don't think the page is going to feature much in the SERPs.
      {{ DiscussionBoard.errors[2655184].message }}

Trending Topics