Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session variable is not working in readfile php method

I've the php code as below. The variable $_SESSION['url'] has value and printing as it is. Its not working if I called the session variable.

session_start();
header('Content-type: application/pdf');
readfile($_SESSION['url']);

But Its working, If we wrote as below.

session_start();
$_SESSION['url']= 'http://samplepdf.com/sample.pdf';
header('Content-type: application/pdf');
readfile($_SESSION['url']);

if anybody experienced this, how to solve this? Thanks in advance

like image 560
user9371102 Avatar asked Mar 21 '26 17:03

user9371102


1 Answers

The $_SESSION is variable (almost) like any other for duration of the script. So if you write it on one line of the script, you can read it later. No matter if sessions work or not in your environment.

So it's not surprising that your second example works. And it does not show anything that could help explaining your problem.

You should show us instead, what did you try to do to make sessions working. And where and how do you actually set the url session variable?

like image 50
Martin Prikryl Avatar answered Mar 23 '26 05:03

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!