Note that there are some explanatory texts on larger screens.

plurals
  1. POphp file runs twice when using header for showing pdf in browser
    primarykey
    data
    text
    <p>strange problem. At least for me. When the link to pdf.php gets clicked, the query writes to the mysql db how many times a certain document has been clicked.</p> <p>The Problem: Instead of writing "1" in the db for every click, it writes "2". It seems that the php file runs twice. But why?</p> <pre><code>$file = './'.mysqli_real_escape_string ($con,$_GET[name]).''; $filename = mysqli_real_escape_string ($con,$_GET[name]); /* Note: Always use .pdf at the end. */ $id = intval($_GET[id]); $date = time(); $what = mysqli_real_escape_string ($con,$_GET[name]); header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file)); header('Accept-Ranges: bytes'); @readfile($file); $sql = "SELECT id,what,person_id,count FROM pdftrack WHERE id = '".$id."' AND what='".$what."'"; $ergebnis = mysqli_query($con,$sql); $row = mysqli_fetch_assoc($ergebnis); if ($row[id] == '') { $sql = "INSERT INTO pdftrack (id,what,date,count) VALUES ('".$id."', '".$what."','".$date."','1')"; mysqli_query($con,$sql);//echo $sql; } else { $count = $row[count]+1; $sql="UPDATE pdftrack SET count='".$count."', date2='".$date."' WHERE id='".$row['id']."' "; mysqli_query($con,$sql); } </code></pre> <p>update: thanks for your help, but it still counts wrong. If the header part is gone, it works like it should. So i think it has something to do with the header part. Any ideas?</p> <p>solution: using only</p> <pre><code>header('Content-type: application/pdf'); @readfile($file); </code></pre> <p>can´t see any downside at the moment.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload