title: Fpdf goes to header Location without generating Pdf.
body: <p>The page automatically redirects to entry.php without generating the pdf. I want it to generate the pdf and then redirect. When the header(Location: entry.php); is removed, it generates Pdf. Is there any other way to achieve it?</p>
  
  <pre><code>include('connection.php');  
  ob_start ();  
  require('fpdf/fpdf.php');  
  
  
  if ($_SERVER['REQUEST_METHOD'] == 'POST')  
  {
      //collect form data
      $name = $_POST['fname'];  
     $lname = $_POST['lname'];  
      $email = $_POST['email'];  
      $gender=$_POST['dropdown1'];  
      $age=$_POST['age'];  
      $qualification=$_POST['qualification'];  
      $fees=$_POST['fee'];  
      $discount=$_POST['discount'];  
      $tobepaid=$_POST['tobepaid'];  
      $paystatus=$_POST['dropdown2'];  
  
  
      $query = "SELECT * FROM details WHERE email = '$email'";  
  $result = mysqli_query($conn, $query) or die (mysqli_error($conn));  
  
  if (mysqli_num_rows($result) &gt; 0) {  
      session_start();  
      $_SESSION['registered'] = "Record Already exists.";  
      mysqli_close($conn);  
      header('Location: entry.php');  
      exit();  
  
  
  }  
      else  
  
  
  $sql = "INSERT INTO details(FirstName, LastName, Email, Sex, Age, Qualification, Fees, Discount, Tobepaid, Paystatus)
   VALUES ('$name', '$lname', '$email', '$gender', '$age', '$qualification', '$fees', '$discount', '$tobepaid', '$paystatus')";  
  
  $result = mysqli_query($conn, $sql);  
  
  
      if( !mysqli_fetch_assoc ($result ))  
  {
  $_SESSION['Msg']= "Submitted Successfully";  
  
  
              class PDF extends FPDF
  {
  // Page header
  function Header()  
  {
  
  
      // Arial bold 15
      $this-&gt;SetFont('Arial','B',15);
      // Move to the right
      $this-&gt;Cell(80);
      // Title
      $this-&gt;Cell(60,10,'Convert HTML TO PDF',1,0,'C');
      // Line break
      $this-&gt;Ln(20);
  }
  
  // Page footer  
  function Footer()  
  {
      // Position at 1.5 cm from bottom  
      $this-&gt;SetY(-15);  
      // Arial italic 8  
      $this-&gt;SetFont('Arial','I',8);  
      // Page number  
      $this-&gt;Cell(0,10,'Page '.$this-&gt;PageNo().'/{nb}',0,0,'C');  
  }  
  }  
  
  // Instanciation of inherited class  
  $pdf = new PDF();  
  $pdf-&gt;AliasNbPages();  
  $pdf-&gt;AddPage();  
  $pdf-&gt;SetFont('Times','',12);  
  
  $pdf-&gt;Cell(0,10,'Name : '.$_POST["lname"],0,1);  
  $pdf-&gt;Cell(0,10,'Email : '.$_POST["email"],0,1);  
  $pdf-&gt;Cell(0,10,'Mobile : '.$_POST["fname"],0,1);  
  $pdf-&gt;Cell(0,10,'Comment : '.$_POST["age"],0,1);  
  
      $pdfname=$_SESSION['UserID'];  
  
  
  $pdf-&gt;Output('Filename.pdf','D');  
  
      header("Location: entry.php");  
  }  
  
  else{
      $_SESSION['errMsg'] = "Invalid Details";
      header("Location: entry.php");
  
  }   
  </code></pre>