Strange CI & Headers Behavior

Hey there,

I posted about another problem in the general app and code development forum that led to me discovering this problem.

I have a controller that outputs an rss feed - all it does it grab some info from the database through a loaded model, and passes the info to the view. That's it - the only thing loaded is my model. The rss feed works fine.

So I am setting some headers right before I output the data.

header("Cache-Control: public, s-maxage=360");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: application/rss+xml;charset=utf-8");

So I check the header output, and it's wrong. It's a date from like 2 months ago. I check the server time and its okay - if I echo gmdate I get the correct value.

Here is the strange part: I've found that the header is pulling the Last-Modified date from the last modified date of the Code Igniter index.php file. If I change the index.php files modified date, the headers change accordingly.

Same thing happens using the output class, and with using the php replace override function.

Anyone know what's going on here? I would post some code but I'm not sure what to post.

[eluser]Randy Casburn[/eluser]
Still having these header problems. And now cross posting in three topics trying to get noticed...
I'd be cautious about bumps and all the cross posts of the same info if I were you. Just sayin'

Do you have mod_info loaded up on your apache server? Can you run info on your Apache server and dump that into code tags? Not php_info(), but your Apache configuration. With all these header issues you've been reporting it might be interesting to see your config.

um...please sanitize the security related stuff first...right.

Hey Randy,

This stopped being a general PHP problem and turned into a Code Igniter problem so I thought I'd bring it to the attention of the CI dev discussion. It's also a new problem not related to my previous discussion a few days ago about the RSS cache. I usually don't post many problems in CI forums since I find all my answers here from older posts, so since I've been having problems nobodies mentioned I figure I should post them. Don't mean no harm.

This is unfortunately on a hosted account where I don't have access to the Apache info, but I'll see if I can contact them and get it.

[eluser]Randy Casburn[/eluser]
No harm to me... won't get the apache config then. Are you using anything weird in your .htaccess files?

Hey Randy,

Here is my .htaccess file:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|internal|files|newsletters|robots\.txt|css|js|public|flash|videos|ajax)
RewriteRule ^(.*)$ index.php/$1 [L]

[eluser]Randy Casburn[/eluser]
Yup..thought so...already saw that .htaccess ..remember ...teehee.

Quote:This stopped being a general PHP problem and turned into a Code Igniter problem
I'm confused. I thought you said you tested this with CI and straight PHP and both acted identically? Doesn't that sort of rule out CI?

Let's assume you're not setting the header for a moment (since it appears that you are not).

So you've told Apache to rewrite every single one of those items in the logically or'd list to the index.php file. So you should expect then that every single one of those items, or the files played back to the browser (in whatever form that is) will have the expiration date of the index.php file. That is what Apache does when the .htaccess file is used in this way.

That doesn't explain your problem, but that explains why everything has the expiration date of index.php.

There is one other thing that trips things up sometimes too. If the date of the http header is the slightest bit behind (older than) the date of the Last Modified header, the server will not send the Last Modified header or the browsers sometimes will ignore (throw away) the Last Modified date.

You may try setting the Last Modified date back a couple of minutes or so to see if that makes a difference.

[quote author="Randy Casburn" date="1214997200"]Yup..thought so...already saw that .htaccess ..remember ...teehee. [/quote]

I checked my old posts to see if I posted this before, but I can't find it - maybe your thinking of some other code I posted?

[quote author="Randy Casburn" date="1214997200"]I'm confused. I thought you said you tested this with CI and straight PHP and both acted identically? Doesn't that sort of rule out CI?[/quote]

I might have explained this wrong - I did a test where I put a php file in the ajax folder and set the headers and checked the output - and it worked fine. So that led me to believe since I was doing the same thing inside CI and it was coming out wrong that it was a CI issue.

I tried setting the Last-Modified timestamp back varying levels with no success - is there a way around the .htaccess file issue?

[eluser]Randy Casburn[/eluser]
No the .htaccess file is doing what you want it to do. Something else is preventing your Last Modified time stamp header from being applied as your HTML is departing your server.

Apache controls this process outbound and your browser has control over this inbound. It's really hard to say what's going on without insight into your Apache set up. Do you know how to use the Tamper Data or Live HTTP Headers plug ins for Firefox? If not, it may be time to investigate what you see coming from the server.

Have tried different browsers, versions, etc? Don't know how else to help you here.

Well, even though this didn't quite get solved the way I wanted it to, it did get solved, so I'll share the "solution".

Although I wasn't able to look at the Apache headers, in my conversations with the support members for the host of the site, they were stumped and said that it appeared to be a problem with Code Igniter.

My own tests confirm what Randy is saying, however, that Apache is doing something to mess with the headers. I found that if I created a file with any extension outside of Code Ingiter and sent a Last-Modified header, it came through fine.

However, with any URL that is a directory (accessing the index file) or a URL explicitly accessing the index.php file, the Last-Modified comes up as the Last-Modified date of that file. So the same essential behavior exists outside of Code Igniter as it does inside.

Moving all the code over to another server worked fine, but didn't solve the problem of that server acting up. The hosting support wasn't able to find out what was causing the problem on the server's end.

Soooo I realized that all the feeds were being published with an extension anyways (that didn't need to access an index.php), so I recreated the RSS and Atom parsers outside of the CI structure. (I have to admit it was a bit of a shock going back to straight PHP for a bit - I never realized how much I take for granted now that I know how Code Igniter saves so much time). I just included a line in the .htaccess to allow the .xml files to be parsed as PHP and away we go - everything worked flawlessly.

Although it is inconsequential for the site, I am still bothered what with Apache is causing it to say "hey, looks like you are trying to send a Last-Modified header. But we've got something totally better. It's the Last-Modified header off the index.php file you're accessing. Trust me, you'll like it." It keeps me up at night.

Thanks to Randy for the help in identifying that it wasn't CI or .htaccess as I was thinking.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.