Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:49:47+00:00 2026-06-08T12:49:47+00:00

I’ve a really weird problem with the following simple php page saved at the

  • 0

I’ve a really weird problem with the following simple php page saved at the root of my webserver as test.php:

<?
if( $_GET['img'] ) {
    header('HTTP/1.0 304 Not Modified');
    die();
} else {
    header("Cache-Control: no-store, no-cache, must-revalidate");
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<body>

<img src="/test.php?img=1">
<a href="/not_existent_page.php">Dead link</a>

</body>
</html>

So when the page gets loaded, my server responds with the following headers:

Status Code 200
Cache-Control   no-store, no-cache, must-revalidate
Content-Type    text/html; charset=utf-8
Date    Wed, 18 Jul 2012 12:00:43 GMT
Server  Apache/2.2.22 (Ubuntu)
Strict-Transport-Security   max-age=172800, includeSubDomains
Vary    Accept-Encoding
x-frame-options sameorigin
x-powered-by    PHP/5.4.4-1~precise+1
x-ua-compatible IE=edge

The interesting part are the cache headers: It says, do not cache!

The request for the picture after loading the page has the following response headers:

Status Code 304
Date    Wed, 18 Jul 2012 12:02:20 GMT
Server  Apache/2.2.22 (Ubuntu)

It does not say anything about caching (but that doesn’t matter anyway, I tested it).

With firefox and chrome the site behaves like it should: Each time I reload the page it gets reloaded as it should. If I click on the link, I get a 404 apache error.

With safari, the following happens:

If I open the page first, I see it.
When I reload the page within a short time (see below what “short time” means) it always gives me a blank site, when I click and the dead link it sometimes gives me a blank site, but I see the following headers in the web developer console of safari:

Status Code 304
Connection:Keep-Alive
Date:Wed, 18 Jul 2012 12:07:41 GMT
Keep-Alive:timeout=15, max=99
Server:Apache/2.2.22 (Ubuntu)
Vary:Accept-Encoding

The page stays blank! But: In my apache server logs, it says it returned all good with status code 200 on page reload:

// first page load
[18/Jul/2012:14:10:12 +0200] "GET /test.php HTTP/1.1" 200 979 "url/test.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2"

// request of picture with answer 304
[18/Jul/2012:14:10:12 +0200] "GET /test.php?img=1 HTTP/1.1" 304 266 "url/test.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2"

// reload within 10 seconds
[18/Jul/2012:14:10:19 +0200] "GET /test.php HTTP/1.1" 200 777 "url/test.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2"

(and a 404 when clicking the dead link.)

And now comes the interesting part: If I wait approx. 10+ seconds after loading the page, Safari behaves as expected: It simply loads the page again on reload without a 304 header (or displays a 404 on the dead link).

I have no problem with firefox and chrome at all.

So my question: Is safari mixing up the headers of the page, but only when loading the page again / clicking on a link within 10 seconds? How can I prevent this? Is this a bug in safari?

Btw: If I change the header to something else, Safari caches that header. So if I change test.php like this:

...
if( $_GET['img'] ) {
    header('HTTP/1.0 204 No Content');
    die();
} else {
....

The page reload now simply aborts without doing anything, but headers I see in safari console are 204 No Content.

One last thing: Reloading the page within 10 seconds triggers the error constantly, while sometimes clicking on the link works in safari, sometimes not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:49:49+00:00Added an answer on June 8, 2026 at 12:49 pm

    /test.php will always set header("Cache-Control: no-store, no-cache, must-revalidate"); There is nothing interesting about the headers saying do not cache because you’re explicitly setting those headers.

    /test.php?img=whatever will NEVER set the Cache-Control headers as above and will always return blank 304 Not Modified. You’re exiting right after the header() call. Technically it is not an image to apache. It’s mime type will be text/html so it will carry your expires/caching as html and php (in your .conf and/or htaccess). Unless you do header('Content-Type: image/jpeg', true); or similar.

    It’s also good to use the second parameter of header() in order to replace previous ones in some circumstances.

    Try this instead. let me know if you get the same result

    <?php
    if (isset($_GET['img'])) {
        header('Content-Type: image/jpeg', true);
        header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified', true, 304);
        exit;
    } else {
        header('Expires: -1', true);
        header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true);
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.