Page 1 of 1

ssl problem creating csv and downloading in IE

Posted: Mon Oct 16, 2006 7:14 am
by gurjit
Hi,

Everything was working until I moved to a SSL connection

I have a button on a page which users click to create a csv file. Below is the code for the button:

Code: Select all

<html>
<head>
<script>
function sage_download() {
window.open('../stationary/accounts_sage_csv.php?frn_meiid=<?php echo $meiid; ?>','password1','scrollbars=no,resizable=no,width=300,height=300,left=50,top=50')
}
</script>
</head>
<body>
<input name="sage" type="button" class="AllFormButton" value="Download Sage File" onClick="sage_download()">
</script>
</body>
</html>
The above simply opens up a popup window calling a file "../stationary/accounts_sage_csv.php" and passing through a variable id. the id references a database field which gets the data to input into the csv file.

Here is the php code for the "../stationary/accounts_sage_csv.php"

Code: Select all

<?php ob_start(); 
require_once('../connections/db_connection.php'); 
require_once('../global_file.php');

$str = "sdfsdf";
echo $str;


header("Cache-control: private"); 
header("Content-Type: application/txt"); 
header("Content-Disposition: attachment; filename=sage_royalties.txt"); 

?>
I get the error when IE tries to download "Internet Explorer cannot download......nts_sage_csv.php?frn_meiid=37 from http://www.mydomain.com Internet Explorer was not able to open this Internet site"


I have narrowed down the problem to the "require_once('../global_file.php');" file. Which contains variables used through out the file. When I dont include this file everything works on SSL connection, with a none SSL connection it all works.

Any ideas?

Posted: Mon Oct 16, 2006 7:32 am
by gurjit
Hi all,

I have further narrowed down the problem.

In the "../global_file.php" there is "session_start();". As soon as you put "session_start();" in, the error occurs. This works on a non-SSL connection

any work arounds

Posted: Mon Oct 16, 2006 7:34 am
by Chris Corbyn
Internet explorer sucks. I don't just say that as an excuse to bash MS because I will now explain the problem.

IE does not know how to download dynamically generated content with cache-control headers set if SSL is being used. The only stop-gap workaround is to dump the file into a tmp directory on the server and then redirect the browser to that file so it's downloading a real file.

I really hope they have fixed this in IE 7.

Posted: Mon Oct 16, 2006 8:10 am
by gurjit
Hi

I found the solution....

if you use session variables in "ob_start()" you must put "session_cache_limiter("must-revalidate");" before "session_start()"

so for example

Code: Select all

<?php
ob_start(); 

require_once('../connections/db_connection.php'); 
session_cache_limiter("must-revalidate");
session_start();

?>

Hope this helps someone