LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   php readfile http VS https (http://www.linuxquestions.org/questions/programming-9/php-readfile-http-vs-https-721389/)

blizunt7 04-24-2009 07:41 AM

php readfile http VS https
 
Hey All,
Doing some force downloading with PHP headers. I have the SAME code on http://www.mywebsite.com and https://secure.mywebsite.com.

I do the following:
Code:

    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Length: ' . filesize($file));
    header('Content-Disposition: attachment; filename=' . basename($filename));
    header('Content-Transfer-Encoding: binary');

    if (readfile("$file"))
    {
        include "dbconnect.php";
     
              ..... CODE to update database .....

        mysql_query($query);
        mysql_close($dbh);
    }
    else
        echo "FALSE";

When I am on the non secure site, i get the box to download the file, as well as my sql statements execute properly. When I am over SSL, I get the box to download the file, however the database does NOT issue the queries and updates. The interesting thing is that if I remove the header and readfile statements, over ssl, the database queries execute correctly. Thus I believe the problem is over SSL with readfile ??


Anyone have any thoughts or ideas?

Thanks a bunch!

paulsm4 04-27-2009 12:32 AM

Dunno. The part that *really* surprised me was that it *worked* if you eliminated the header and readfile() statements.

So I guess your next step is to narrow it down to one (header) or the other (readfile).

Please post back what you find!

Thanx in advance .. PSM

blizunt7 04-28-2009 07:35 AM

Hey Paulsm4,
What I have also found is that if I change the ORDER of the code so that the SQL statements execute first, and then i issue the readfile, without checking if(readfile(file)); the SQL statements query properly, and the readfile pushes the file to the browser properly.

Code:

        include "dbconnect.php";
     
              ..... CODE to update database .....

        mysql_query($query);
        mysql_close($dbh);

        readfile("$file");

So I believe something to be wrong with readfile over SSL. Maybe not "wrong" but functioning differently than over HTTP.

paulsm4 04-28-2009 11:18 PM

OK, good. So we know the only two variables are:

1. readfile()
2. HTTPS

So the next step is to throw all the error checking ou can at "readfile()" (starting with a meaningful error#, if any).

Keep us posted!

PS:
You might also want to try "is_readable($filename)"...

PPS:
Here are some good tips on PHP error handling/error debugging:
http://www.w3schools.com/php/php_error.asp
http://www.tutorialspoint.com/php/ph...r_handling.htm


All times are GMT -5. The time now is 04:32 PM.