LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-24-2009, 08:41 AM   #1
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Rep: Reputation: 30
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!
 
Old 04-27-2009, 01:32 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 04-28-2009, 08:35 AM   #3
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
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.
 
Old 04-29-2009, 12:18 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 04-29-2009 at 02:04 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php https wrapper giving Segmentation fault but not http imraven Linux - Software 2 03-27-2009 03:20 AM
redirect http to https awreneau Linux - Server 17 10-14-2008 10:13 AM
http and https wennie Linux - Software 1 04-01-2005 12:47 PM
HTTP to HTTPS shegde Linux - Software 8 01-31-2003 05:29 AM
https or http? antken Programming 3 10-30-2002 06:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration