PHP Last-Modified header not sent? - php

So I have this at the very top of my PHP file:
<?php
// Set headers
header('Content-Type: text/html; charset=UTF-8');
header('Content-Style-Type: text/css');
header('Content-Script-Type: application/javascript');
header('HTTP/1.1 200 OK');
header('Content-language: en-US');
header('X-Powered-By: ');
header_remove('X-Powered-By');
header('Last-Modified: Tue, 01 Jan 2013 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, max-age=0, must-revalidate');
header('Pragma: no-store, no-cache, max-age=0, must-revalidate');
header('Expires: Tue, 01 Jan 2013 00:00:00 GMT');
?>
So when I check the Firefox console's NET tab on my site's URL I don't see the Last-Modified header. Any suggestions?

You're telling the browser to cache nothing and he MUST revalidate everything. So the last-modified header doesn't matter.

Related

Clear site browser cache in php

trying to Clear browser site cache in php,
for firefox browser is working fine, as we want but when i run in chrome it didnt work.
see code,
header('Clear-Site-Data: "cache", "cookies", "storage", "executionContexts"'); //Firefox
// Crome
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header('Clear-Site-Data: "cookies"');
return $this->getSuccessResponse("Token Valid");
I think you can't clear cache from browser perfectly, one only option is you can do manually. There is some code. I hope it will work.
<?php
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

PHP echos file as text instead of binary on server

I have written a PHP page which reads a file and does echo it after adding some headers:
header('Content-disposition: filename="' . $fname . '"');
header('Pragma: no-cache');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header("Content-type: $AttachFileType");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($ffullname));
echo file_get_contents($ffullname);
This piece of code does well on local test, but when porting to the server, the response is not as expected. For example when I want to retrieve a png file, I get the below image on local test:
while server test outputs this one:
As I have investigated, the only difference of them is 4 additional headers on server response. Local test response headers:
Cache-Control: must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Content-disposition: filename="attachment_hrmstotal_generalskills_6.png"
Content-Length: 2401
Content-Transfer-Encoding: binary
Content-Type: png
Date: Wed, 23 May 2018 04:45:02 GMT
Expires: 0
Keep-Alive: timeout=5, max=97
Pragma: public
Server: Apache/2.4.27 (Ubuntu)
and server response headers are these:
Cache-Control: must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-disposition: filename="attachment_hrmstotal_generalskills_1.png"
Content-Length: 184450
Content-Transfer-Encoding: binary
Content-Type: png
Date: Wed, 23 May 2018 04:40:56 GMT
Expires: 0
Pragma: public
Server: nginx/1.8.0
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
The last four headers is the difference. What is the problem, its reason and how to solve it?
Your content-type should be Content-type: image/png

Which is best way to clear cache when my site opens in browser?

i have put this code in my index.php i need to put this code in all my page or just this code works in index page ?
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
?>

Php CSV export UTF8 encoding causing incorrect excel format

i tired doing an csv export. I needed two languages (tamil and english) in the sheet using normal headers
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
header ( 'Content-Type: application/vnd.ms-excel') ;
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
echo $content;
This was causing problems in the tamil characters being displayed. But the format of the excel was fine. So i used a UTF8 encoding to display the tamil characters as shown below.
$now = gmdate("D, d M Y H:i:s");
header('Pragma: public');
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Last-Modified: {$now} GMT");
header('Content-Type: text/csv');
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
echo chr(255) . chr(254) . mb_convert_encoding($content, 'UTF-16LE', 'UTF-8');
This helped with the characters and both languages are being displayed fine now but the format of the csv being generated is disrupted. Everything is being displayed in a single column. Is there anyway to solve this?

How to prevent from session restore on back button in ubuntu?

Guys please tell me how to prevent from session restore on back button in ubuntu ?
session_cache_limiter( FALSE );
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate, post-check=0, pre-check=0'");
header("Pragma: no-cache");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
this works in xp but not in ubuntu.

Categories