0

I have user permissions on my .html files other than 0744. They are actually set to 0700 so to get around this, I have suPHP set up, and I use a load.php file to access and load all the files. The file in question is a simple .html file like so:

test.html (0700):

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="test.css" />
    </head>

    <body>
        <p> why is this not working?</p>
    </body>
</html>

test.css (0744):

body
{
    background-color:#bbcbde;
}    
p
{
    background-color:#bfc4de;
    color:'red' ;
    border:'solid black';
    font-size:35pt;
}

load.php (0744):

$page = $_GET['page'];
header("Location: http://www.example.com/" . $fileName);
exit;

Note: the css file I have set to normal 0744 permissions for debugging purposes.

If I type http://www.example.com/load.php?page=test.html the page loads find. However, I suspect that the css file is being used from a cache because none of the changes to test.css are applied to test.html. If I remove the line

<link rel="stylesheet" type="text/css" href="test.css" />

The change is reflected as the background becomes white again. However, if I move the css file to, for example test2.css, and change the style (ie. different colors) and link to that instead, the changes are suprisingly not applied. If I move test.css to test2.css without linking to the new name (similar to deleting the file), the css effect is still applied! Similarly if I chmod test.css to 0000 it still uses the style sheet. Also I know the .css file is not corrupted because I con open up test.html locally on my machine.

Does anyone have any idea what's going on because I don't have the foggiest.

EDIT as per Murray McDonald's answer below, I traced down the problem to having to do with a 304: Not Modified status code. Why Is this being returned when the file has clearly changed?

puk
  • 16,318
  • 29
  • 119
  • 199

2 Answers2

1

Whenever I run into something mysterious like this I eavesdrop on the HTTP protcol going back and forth between the browser and the server by using "fiddler2" -- it works in MSIE and Firefox. You can easily see the reuest headers the response headers request body, response body (if any) etc.

Murray McDonald
  • 631
  • 4
  • 5
  • thanks, I'll give it a try. Any advice as to what I should look for? – puk Jan 11 '12 at 13:39
  • An easier solution if you use chrome (or can't get fiddler2 in linux) here http://stackoverflow.com/a/3019085/654789 – puk Jan 11 '12 at 13:47
  • well your answer was hugely helpful. It shows 304: Not Modified. – puk Jan 11 '12 at 13:49
  • Yeah that's what one would expect -- the question now is why does it think it hasn't been modified? Is there an HTTP HEAD request being sent by your browser -- I've seen cases where the file was cached by an ISP and the request isn't even getting to the target server -- you need to look at the server's log to see if the requet is making it o the server -- if it isn't then you need to send out the correct headers to ensure your file can only be cached by the end user and not in any intermediate caches along the way – Murray McDonald Jan 11 '12 at 14:15
  • I just stated below how I had two `.css` files. All I had to do to fix it was issue a `chdir` command in `load.php` it's funny b/c it was loading `test.html` in the current folder, not in the folder specified by its absolute path =P – puk Jan 11 '12 at 14:23
  • Hmmm -- although that may have worked it can't possibly be the "right solution" -- if you look at your server logs at the request for "http:/yourdomain.com/load.php?page=test/test.thml" following you should see the request generated by having sent out the Location header -- what exacxtly does that request look like? – Murray McDonald Jan 11 '12 at 14:42
  • They seem to confirm my previous solution: 200 when the `.css` file was loaded, 302 when it had not changed, and 404 when it wasn't found (I moved/deleted it) – puk Jan 11 '12 at 23:13
0

I figured out what my problem (albeit with great support from Murray). I have my folders set up like so

/
├── test
│   ├── test.html
│   └── test.css
├── load.php
└── test.css

I thought that

header("Location: http://www.example.com/" . $fileName);

would launch the page from within the correct folder, but even if I type the following into the browser

http://www.example.com/load.php?page=test/test.html

module.php, when searching for test.css returns /test.css and not /test/test.css which is what I want. Now, the question is how I tell php to set the working directory.

puk
  • 16,318
  • 29
  • 119
  • 199
  • Its your web server that resolves URLS and maps them to files in the file system. Are you using Apache as the server? – Murray McDonald Jan 11 '12 at 14:24
  • yes apache2.0, and had I typed `http://www.example.com/test/test.html` apache would have been smart enough to load `test/test.css` but for some reason, when returned from `load.php` it's not smart enough to do this. It's like when you do `vim Documents/index.html` and you issue the command `:sh` and you do `ls`, it shows you the folder with `Documents` in it, not `index.html` – puk Jan 11 '12 at 23:17
  • Hi puk -- your load.php is issuing a "Location" header to the client browser -- the client browser is supposed to send in the request in that header -- so in theory there should be no difference between you typing the URL in directly in your browser (http://www.example.com/test/test.html" or if you invoke http://www.example.com/load.php?page=test/test.html) – Murray McDonald Jan 11 '12 at 23:58
  • But obviously there MUST be some difference -- that's why I am asking you to look at the Apache access logs -- I did LAMP and WAMP development and administration for 8 years (including lots and lots of mod_rewrite and reverse proxying) and I have NEVER EVER even considered changing the working directory in a PHP script - shouldn't be at all necessary if the correct URLS are being requested -- have a good evening! – Murray McDonald Jan 12 '12 at 00:00
  • @MurrayMcDonald yes that **also** occurred to me that the `Location` header should act as a redirect, so it still should work on files with permission 0700. I too think I am doing something wrong. My initial idea was to use `file_get_contents($fileName)`. Do you think that is better? – puk Jan 12 '12 at 00:16
  • @MurrayMcDonald hey if you are a LAMP expert, what would your advice be on using unix permissions for html? I am currently using suPHP for php/javascript code snippets, but html is much more sensitive. For example, returning it the wrong way might bypass the cache. I highly doubt there is such a thing as suHTML =P – puk Jan 12 '12 at 13:42