homepage Welcome to WebmasterWorld Guest from 54.161.166.171
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod expires - effect on an <img> tag with a PHP script as source
jdbnd




msg:4043639
 8:31 pm on Dec 15, 2009 (gmt 0)

I use a pixel tag on one of my partners' websites with the following code:

<img border="0" width="1" height="1" src="http://www.example.com/somedirectory/somescript.php?somevariable">

In the .htaccess file for that site (example.com), I have the following code:

---------------------------

ExpiresActive On
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/plain "access plus 1 day"
ExpiresByType text/javascript "access plus 1 day"
ExpiresByType image/gif "access plus 3 months"
ExpiresByType image/png "access plus 3 months"
ExpiresByType image/jpeg "access plus 3 months"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"

---------------------------

My question is, would any of the code in .htaccess cause the pixel tag/script to be cached, instead of loaded anew every time someone hits a page that contains it?

I'm experiencing an issue where the pixel tag is only picking up the first page view, and is supposedly being served up on subsequent pages but is not firing.

Thanks!

J

 

jdMorgan




msg:4043705
 10:08 pm on Dec 15, 2009 (gmt 0)

That depends on how precisely your Web beacon is being output by somescript.php. If it is included (e.g. using 'require') as a file, and sent to the client using proper Cache-Control and Expires headers, it should work. I'd suggest 'Expires: A0' and 'Cache-Control: "no-store"'

If on the other hand, your script redirects to that image, then it will be affected by the ExpiresByType settings above (I assume it's a 1x1 transparent .gif image, 43 bytes, etc).

You can use the "Live HTTP Headers" add-on for Firefox/Mozilla browsers to view the HTTP headers passing back and forth between your server and your browser to confirm or rule out the redirection and to check the Expires and Cache-control headers.

Jim

jdbnd




msg:4043715
 10:26 pm on Dec 15, 2009 (gmt 0)

It actually doesn't send any image whatsoever. The script ("somescript.php") is pure PHP, and just does some server-side processing and then makes an entry in MySQL.

Joe

jdbnd




msg:4043721
 10:33 pm on Dec 15, 2009 (gmt 0)

All it needs in order to work is a request from the browser - it takes the IP address and the timestamp of the request, and then does its thing on the server side.

Joe

jdMorgan




msg:4043740
 11:03 pm on Dec 15, 2009 (gmt 0)

OK, but what response does it return to the client? Check out the HTTP headers to get an answer to your question.

Jim

jdbnd




msg:4043769
 11:51 pm on Dec 15, 2009 (gmt 0)

HTTP Status Code: HTTP/1.1 200 OK
Date:Tue, 15 Dec 2009 23:49:57 GMT
Server:Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.11
X-Powered-By:PHP/5.2.11
Vary:Accept-Encoding
Content-Encoding:gzip
Content-Length:20
Connection:close
Content-Type:text/html

jdbnd




msg:4043781
 12:10 am on Dec 16, 2009 (gmt 0)

Did some more testing - caching is definitely the culprit. I'd love to keep the caching in effect for other things on the site - can I exclude specific files like this one (specify different caching settings) using mod_expires or do I have to use mod_headers or something else?

Thanks,
Joe

jdMorgan




msg:4043791
 12:21 am on Dec 16, 2009 (gmt 0)

You'd need to use both, inside a <Files> or <FilesMatch> container.

Alternately, just modify your PHP script to output these headers along with the 200-OK status for the tracking URL requests. You should actually be returning the "text" of a 1x1 transparent .gif file too, for the 'cleanest' implementation. Othewise, some browsers *may* throw a broken image icon on the page, which makes your tracking "quite non-transparent."

The 'normal' way to do all of this would be to link to 'tracking.gif?afid=1234', rewrite (mod_rewrite) that request to your tracking script when it arrives at your server, serve the requested transparent 1x1 .gif image by 'including' it from within your script, and send along the 200-OK status and cache-control headers, making the image non-cacheable.

Jim

jdbnd




msg:4043804
 12:46 am on Dec 16, 2009 (gmt 0)

Thanks - that's helpful. I've made the minor changes to htaccess for now and everything appears to be working. At some point I'll clean up the whole pixel method too. Appreciate the quick responses.

jdbnd




msg:4044529
 3:35 am on Dec 17, 2009 (gmt 0)

Jim, are there other disadvantages besides the potential broken image icon to doing it the way I'm doing it, versus the "cleaner" way?

Thanks,
Joe

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved