Page is downloaded instead of rendered over SSL - php

I have my checkout page secured on my site with the Bluehost SSL certificate and quite frequently the page will be downloaded instead of rendered.
This only happens when I use ssl, if I run the site without it the page loads fine.
Is there anything i can do to prevent this, I have tried placing
<?php header("Content-type: text/html"); ?>
at the top of the page but this doesn't solve the issue. Here is an example of the file headers that are downloaded when the issue occurs:
HTTP/1.1 200 OK
Date: Sun, 12 Dec 2010 23:42:18 GMT
Server: Apache
X-Powered-By: PHP/5.2.14
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
Here is an example of the headers when it loads correctly:
HTTP/1.1 200 OK
Date: Mon, 13 Dec 2010 03:04:08 GMT
Server: Apache
X-Powered-By: PHP/5.2.14
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Keep-Alive: timeout=10, max=28
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

I found the issue was being caused by my css and javascript minifier script, "CSS and Javascript Combinator". When I swapped it out to use "Minify" the issue was resolved.

Does the header header("Content-disposition: inline"); help?

You need to tell apache its OK to use SSL with php files.
Have you got the correct stanza in the extra/httpd-ssl.conf
It should look something like:-
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>

Related

Magento does not set cookie on product/category page

So here is the issue, Magento doesn't seem to set-cookie on product/category page.
It doesn't show any cart items or customer login information on product page, however all the items appear fine on home page and rest of the pages on site.
I checked headers for two of the pages.
Here is the product page:
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Tue, 15 Mar 2016 05:01:57 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Vary: Accept-Encoding
X-Cacheable: NO:Cache-Control=no-cache
Accept-Ranges: bytes
X-Served-From-Cache: Yes
Here is the home page headers (which is working fine)
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Tue, 15 Mar 2016 05:02:12 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Set-Cookie: frontend=n7m2mbnoo861h84r9ma40of221; expires=Wed, 16-Mar-2016 05:02:12 GMT; path=/store/; domain=-----; HttpOnly
Vary: Accept-Encoding
X-Cacheable: NO:Cache-Control=no-cache
Accept-Ranges: bytes
X-Served-From-Cache: Yes
Any idea what's happening?
I have tried increasing cookie lifetime to 86400
and cookie path to /store/ and cookie domain to (www.mydomain.com)
It turns out issue was misconfiguration of varnish on server. It was serving cached pages. Solution: Restarted varnish.

Readfile image not working on PHP

I have the below PHP code to load image
header('Content-Type: image/'.$contentFormat);
header('Content-Length: '. filesize($image));
readfile($image);
When I request the url in console I get the bellow header response
HTTP/1.1 200 OK
Date: Fri, 28 Nov 2014 13:13:59 GMT
Content-Type: image/jpeg
Content-Length: 107885
Connection: keep-alive
Keep-Alive: timeout=30
Server: Apache/2
X-Powered-By: PHP/5.3.13
Set-Cookie: PHPSESSID=617a3a6eba912178f810f10cc5d171f3; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Accept-Ranges: bytes
Age: 0
ÿØÿà
including ÿØÿà,
What could be the problem? I searched all my php files for whitespace. Any guess or suggestions where I can search for the whitespace

Setting content-type using nginx and PHPExcel

I'm developing a site using Zend Framework 2 where the client wanted to be able to export some data to an Excel file. For this I went with PHPExcel, and I got it working on my local computer, where I run Apache2.
<?php
//Create a writer for Excel
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
// Get the data from php://output
// https://stackoverflow.com/questions/16551375/phpexcel-in-zend2-controller
ob_flush();
ob_start();
$objWriter->save('php://output');
$excelOutput = ob_get_clean();
//Get a new response object
$response = new \Zend\Http\Response();
//Set headers for the response object
$response->getHeaders()
->addHeaderLine('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT')
->addHeaderLine('Cache-Control: no-store, no-cache, must-revalidate')
->addHeaderLine('Cache-Control: post-check=0, pre-check=0')
->addHeaderLine('Pragma: no-cache')
->addHeaderLine('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
->addHeaderLine('Content-Disposition: attachment;filename="report.xlsx"');
//Set the content for the response object
$response->setContent($excelOutput);
return $response;
?>
The problem is that when I uploaded the project to my production server, running Nginx with a pretty standard setup using PHP-FPM, the Excel file isn't sent using the correct headers. It seems like they are overwritten with "text/html" which makes the browser show some garbled characters instead of making the file available for download.
I followed this (PHPExcel in Zend2 Controller) question for getting the content into a variable.
I can't figure out why this is happening, are the headers set differently using PHP on Apache2 than running Nginx with PHP-FPM?
Update: Returned headers
Apache on local computer:
HTTP/1.1 200 OK
Date: Sun, 11 May 2014 11:24:09 GMT
Server: Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.19
X-Powered-By: PHP/5.4.19
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Last-Modified: Sun, 11 May 2014 11:24:09 GMT
Content-Disposition: attachment;filename="report.xlsx"
Content-Length: 6551
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Nginx headers:
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sun, 11 May 2014 11:14:18 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.3.10-1ubuntu3.11
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip

How to enforce browser caching?

I have php script that serve image from the script
i expect the browser to cache the image even its come from the api.
I have read the thread How to browser cache image from php
and
How to force a web browser to cache Images
that to modify Expires header, I've tried it but is seem got no luck
I've manually
header('Content-Type : image/jpeg');
header('Content-Size : 2759' );
header('Cache-Control : public, max-age=2592000' );
header('Pragma : public' );
header('Expires: ' . date('r', time() + 30*24*60*60 ));
my response header from my output is :
Server: nginx/0.8.54
Date: Tue, 06 Dec 2011 11:20:17 GMT
Content-Type: image/jpeg
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.3.7-ZS5.5.0 ZendServer/5.0
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public, max-age=2592000
Pragma: no-cache
Expires: Wed, 05 Dec 2012 18:20:17 +0700
Content-Size: 2759
as you can see, the headers is modified, but in cache-control header it still have no-store and no-cache value,
is this nginx configs things or can be resolved from php, and how ??
thank you in advance....

Disable Gzip compression for single php file with IIS

I have a configuration that doesn't seem too common on the Internets (PHP with IIS), and so far I have not been able to find a solution for my problem because of this.
Basically when I'm sending a manual 404 header on my php page:
header('HTTP/1.0 404 Not Found');
The problem is that I then always get encoding errors, which I've determined has something to do with gzip being enabled.
When I curl with --compressed I get:
HTTP/1.1 404 Not Found
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 3560
Content-Type: text/html
Content-Encoding: gzip
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Vary: Accept-Encoding
Server: Microsoft-IIS/6.0
Set-Cookie: PHPSESSID=b0ueqhtc3o4p7m2luqss170fr3; path=/
Date: Mon, 11 Jul 2011 16:15:40 GMT
curl: (61) Error while processing content unencoding: invalid code lengths set
Is it possible to disable compression just for this one page? Or is there some other solution for this that I'm missing? I don't want to disable compression for the entire site.
This is simple, just use the ini set like so:
<?php
if(ini_get('zlib.output_compression')){
ini_set('zlib.output_compression', 'Off');
}
header('HTTP/1.0 404 Not Found');
?>
Simple as that.

Categories