943,083 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 19745
  • PHP RSS
May 20th, 2009
0

how to add expires header to images?

Expand Post »
How can i add expires header to images?
i used the following in css file and php respectively
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. -----------CSS------------------------------------------------------
  3. ob_start ("ob_gzhandler");
  4. header ("content-type: text/css; charset: UTF-8");
  5. header ("cache-control: must-revalidate");
  6. $offset = 48 * 60 * 60;
  7. $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
  8. header ($expire);
  9. ?>
  10. ----------PHP------------------------------------------------------
  11. <?php
  12. if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
  13. ob_start("ob_gzhandler");
  14. else
  15. ob_start();
  16. header ("content-type: text/html; charset: UTF-8");
  17. header ("cache-control: must-revalidate");
  18. echo $offset = 48 * 60 * 60;
  19. $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
  20. header ($expire);
  21. ?>

Both are working but it does not applies to the images used in css files. They need to be specified separately.
How?
This is my problem can any one help me please...
Also if u can please tell me how to specify Etags?

I also tried in another method using .htaccess
PHP Syntax (Toggle Plain Text)
  1. <IfModule mod_expires.c>
  2. ExpiresActive On
  3. ExpiresByType image/gif A2592000
  4. ExpiresByType image/jpg A2592000
  5. ExpiresByType image/png A2592000
  6. ExpiresByType application/x-javascript A2592000
  7. ExpiresByType text/css A2592000
  8. ExpiresByType image/x-icon A2592000
  9. </IfModule>
i think this is working but not working for icon files
i also don know what this means "A2592000"
how can i set my own time for as expire header?

Thanks in adavance.
Similar Threads
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
danishbacker is offline Offline
97 posts
since Apr 2008
May 21st, 2009
0

Re: how to add expires header to images?

Problem solved. The second method is working.
Using .htaccess
PHP Syntax (Toggle Plain Text)
  1. <IfModule mod_expires.c>
  2. ExpiresActive On
  3. ExpiresByType text/html "access plus 2 days"
  4. ExpiresByType image/gif "access plus 60 days"
  5. ExpiresByType image/jpg "access plus 60 days"
  6. ExpiresByType image/png "access plus 60 days"
  7. ExpiresByType application/x-javascript "access plus 60 days"
  8. ExpiresByType text/css "access plus 60 days"
  9. ExpiresByType image/x-icon "access plus 360 days"
  10. </IfModule>

Also i got the meaning of A2592000 = 720hours = 30days
the numbers after A is the time to expire time (in seconds)
ie A3600 is 1 hour

Thank you all.
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
danishbacker is offline Offline
97 posts
since Apr 2008
Sep 24th, 2009
0

Re: how to add expires header to images?

Thanks a lot man!
I registered just to say THANKS to you!

Cheers!



Problem solved. The second method is working.
Using .htaccess
PHP Syntax (Toggle Plain Text)
  1. <IfModule mod_expires.c>
  2. ExpiresActive On
  3. ExpiresByType text/html "access plus 2 days"
  4. ExpiresByType image/gif "access plus 60 days"
  5. ExpiresByType image/jpg "access plus 60 days"
  6. ExpiresByType image/png "access plus 60 days"
  7. ExpiresByType application/x-javascript "access plus 60 days"
  8. ExpiresByType text/css "access plus 60 days"
  9. ExpiresByType image/x-icon "access plus 360 days"
  10. </IfModule>

Also i got the meaning of A2592000 = 720hours = 30days
the numbers after A is the time to expire time (in seconds)
ie A3600 is 1 hour

Thank you all.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bbrosg is offline Offline
1 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Regarding multiple Pagination
Next Thread in PHP Forum Timeline: PHP Ethical Issues Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC