-1

I am using mPDF for PDF generation in PHP. It is working fine with no issue. What I want if user is not logged in then I would like to show error in alert box and after that redirect to index.php.

But due to some reason that I don't know it is not showing any alert box nor redirect. It seems like JavaScript is not working.

Here is the code:

<?php
session_start();
$uid=$_SESSION['uid']; 
  if($uid== "" or $uid == NULL)
{

    echo '<script type="text/javascript">window.alert("Please login first to access this page."); </script>';
    echo '<script type="text/javascript">window.location.href("/index.php");</script>';
}

Above code is top of the file and now below I have these code for mPDF:

include("pdf/mpdf.php");
$mpdf=new mPDF(''); 
$stylesheet = file_get_contents('pdf/tablecss.css');
$mpdf->WriteHTML($stylesheet,1);
//==============================================================

//$mpdf->WriteHTML($html);
$mpdf->SetDisplayMode('fullpage');

$mpdf->SetWatermarkText('                        www.somewebsite.com               ');
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->showWatermarkText = true;

$mpdf->WriteHTML($html);

$html = '
<html>
<head>
<style>
....
halfer
  • 19,824
  • 17
  • 99
  • 186
Roxx
  • 3,738
  • 20
  • 92
  • 155

1 Answers1

0

I fixed that. What i did is i put mPdf code inside else.

Like this and it works.

if($uid== "" or $uid == NULL)
{

    echo '<script type="text/javascript">window.alert("Please login first to access this page."); </script>';
    echo '<script type="text/javascript">window.location.replace("/index.php");</script>';
}else{

    mpdf code goes here
Roxx
  • 3,738
  • 20
  • 92
  • 155