| | |
Sessions, Headers & PDF
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi,
I'd be grateful for a little help. I have a script which generates invoices as PDF files and stores above just above www level (so they cannot be access directly via a URL).
I would like users to be able to access their own invoices but nobody elses.
My script as it stands is as follows:
I've posted a slimmed down the code here and changed a few variable names for security reasons but essentially its the same as what I'm working with.
The basic codes works. The problem arises when an authorised user calls the file. The PDF file is returned, it is not rendered correctly e.g. you see "%PDF-1.7 3 0 ...". I presume this is because session_start() acts like a header? Is there any way round this.
I'd be grateful for a little help. I have a script which generates invoices as PDF files and stores above just above www level (so they cannot be access directly via a URL).
I would like users to be able to access their own invoices but nobody elses.
My script as it stands is as follows:
PHP Syntax (Toggle Plain Text)
<?php session_start(); if($_SESSION['auth']==false){ header("HTTP/1.0 404 Not Found"); exit(); } $invoice_id = $_GET['vid']; $user_id = $_SESSION['userid']; if (is_numeric ($invoice_id)) { require(db.php); $q = $dbh->query(...); $n = $q->fetchColumn(); if($n==1){ //output pdf $filename = "../invoices" . $invoice_id . ".pdf"; header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="invoice.pdf"'); readfile($filename); } }
I've posted a slimmed down the code here and changed a few variable names for security reasons but essentially its the same as what I'm working with.
The basic codes works. The problem arises when an authorised user calls the file. The PDF file is returned, it is not rendered correctly e.g. you see "%PDF-1.7 3 0 ...". I presume this is because session_start() acts like a header? Is there any way round this.
Last edited by ANicholson; Aug 25th, 2009 at 9:48 am.
Try to turn on output buffering (should be the 1st line of your code) and as the last line to flush the buffered output.
php Syntax (Toggle Plain Text)
<?php ob_start(); ?>
php Syntax (Toggle Plain Text)
<?php ob_flush(); ?>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Aug 2009
Posts: 3
Reputation:
Solved Threads: 0
Just to clarify, like so?
If so, no joy
php Syntax (Toggle Plain Text)
<?php ob_start(); // .. all my other code ob_flush(); ?>
If so, no joy
![]() |
Similar Threads
- Email FUnction with PHP & PDF pr Word FOrmat (PHP)
- [Acrobat Pro] Excel to PDF - No Hyperlinks? (Windows Software)
- Banners, Headers, & Titles of website: How to share it among all the pages? (HTML and CSS)
- How to open access file & pdf file using visual basic? (Visual Basic 4 / 5 / 6)
- Precompiled Headers & Unexpected EOF error (C++)
Other Threads in the PHP Forum
- Previous Thread: CakePHP installation problem
- Next Thread: Include, cant make it work
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date development directory display download dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parse parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql structure syntax system table thesishelp tutorial update upload url validation validator variable video web xml youtube






.
Wohoo! Good luck..
