I have an html page with a form and a submit button.
Once I click submit all the form data, thanks to fpdf, gets turned into pdf.
This pdf is sent without problems to my email.
Building this little page everything always worked without problems and I was able to redirect my user to a thank you page without problems with this code:
header("Location: /thank-you.php",303);
exit();
As soon as I’ve implemented the pdf file save the final redirection stopped working.
I’ve implemented the pdf save easily with fpdf:
$pdf->Output("filename.pdf", "D");
And reading on stackoverflow and all the internet I’ve understood that you can’t send two headers.
I thought about solving the problem with javascript so I put after the pdf generation
echo "<script language=javascript>
window.location = 'thanks.html'
</script>";
but no luck.
The php page simply “stops” when the browser downloads the pdf file.
Any chance to solve this?
EDIT:
All the suggestion I got (thanks to everybody) get me to the same point: use thank you page to handle the pdf save.
Sounds great to me.
I’ve tried preparing a thankyou.php page with a simple $pdf->Output(); in it.
It didn’t work…
So I thought to use an include to my create.php (where happens all the magic: pdf creation, email sending, insert into db etc) with:
<?php
include("create.php");
$pdf->Output();
?>
Still no luck.
What’s wrong with my thinking?
You should approach this the other way around.
Send the user to the thanks page, and on that thanks page do
$pdf->Output(). That should do what you want.