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 3443332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:46:42+00:00 2026-05-18T08:46:42+00:00

Question I am running a bit of an experiment and could use some help.

  • 0

Question

I am running a bit of an experiment and could use some help.
I have created 2 files. main-real.css which is a standard plain ol’ css file, and main.css which is parsed by PHP and has an include() which grabs the former real css file.
Here is the code for main.css:

<?php 
include("main-real.css");
?>

I am then adding an instruction to my .htaccess file to parse this css file with PHP:

<FilesMatch "main.css">
AddHandler application/x-httpd-php5 .css
Header Set Content-Type "text/css"
</FilesMatch> 

This works perfectly on my PHP 5.2 server running Apache.
The issue is that this file does not appear to be cached by the browser, or at least does not return a
304 Not Modified Status code like the regular un-PHP-parsed CSS file.

Here are the headers for main-real.css if accessed directly:

RESPONSE HEADERS
    Date..............Thu, 18 Nov 2010 22:10:57 GMT
    Server............Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
    Last-Modified.....Thu, 18 Nov 2010 22:10:23 GMT
    Etag.............."11b010a-26-4955b0e6671c0"
    Accept-Ranges.....bytes
    Content-Length....38
    Content-Type......text/css

REQUEST HEADERS
    Accept.............text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language....en-us,en;q=0.5
    Accept-Encoding....gzip,deflate
    Accept-Charset.....ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive.........115
    Connection.........keep-alive
    Cookie.............fc=fcVal=7625790752294348480
    If-Modified-Since..Thu, 18 Nov 2010 22:10:23 GMT
    If-None-Match......"11b010a-26-4955b0e6671c0"
    Cache-Control......max-age=0

Here are the headers for the PHP parsed main.css:

RESPONSE HEADERS
    Date...............Thu, 18 Nov 2010 22:11:11 GMT
    Server.............Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
    X-Powered-By.......PHP/5.2.11
    Content-Type.......text/css
    Keep-Alive.........timeout=5, max=97
    Connection.........Keep-Alive
    Transfer-Encoding..chunked

REQUEST HEADERS
    Accept.............text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language....en-us,en;q=0.5
    Accept-Encoding....gzip,deflate
    Accept-Charset.....ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive.........115
    Connection.........keep-alive
    Cookie.............fc=fcVal=7625790752294348480
    Cache-Control......max-age=0

I have tried modifying the http-headers in all sorts of ways, adding max-age, last-modified and others with no success. Is there something I am missing or misunderstanding?


Solution & Final Code

The main missing piece of code was that I needed to send the Last-Modified header prior to the include(). This needs to be done within the PHP file itself! I previously tried adding Last-Modified using an .htaccess Header set instruction, and although that does add the appropriate header, it did not trigger caching.
Here is my final code for main.css with far-future Expires headers and Cache-Control for good measure.

<?php
$last_modified = date("D, d M Y H:i:s \G\M\T", filemtime("main-shared.css"));
$expiration = date("D, d M Y H:i:s \G\M\T", strtotime('+1 year'));

header("Cache-Control: public, no-transform");
header("Expires: $expiration");
header("Last-Modified: $last_modified");

include("main-shared.css");
?>
  • 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-05-18T08:46:43+00:00Added an answer on May 18, 2026 at 8:46 am

    What headers Apache would send for main-real.css is irrelevant, because you are include() ing that file through the file system.

    You need to send the same headers through your PHP script before you include the other file.

    header("Cache-Control: ........ ");
    header("Expires: ....... ");
    ....
    include("main-real.css"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of an unusual question. I'm running an old DOS game
Multiple part question on running gvim on windows xp. I have a _vimrc file
I have a question about debugging a running C++ program in Linux. If a
Quick JUnit question. I'm running some unit tests that involve starting up the GUI
I'm running a MapReduce task on Gzipped .arc files. Similar to this question ,
I have a basic question. I would like to make running Arc.py several times
Ok so this question has been bothering me for some time. I'm running a
I have a rails app running on port 3000. The page in question has
This question concerns running python files in terminal that are not stored in the
I'm a bit confused on url writing in .htaccess and have a question about

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.