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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

thanks, I'll give it a try. Any advice as to what I should look for?
An easier solution if you use chrome (or can't get fiddler2 in linux) here stackoverflow.com/a/3019085/654789
well your answer was hugely helpful. It shows 304: Not Modified.
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
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
|
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.

6 Comments

Its your web server that resolves URLS and maps them to files in the file system. Are you using Apache as the server?
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
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 (example.com/test/test.html" or if you invoke example.com/load.php?page=test/test.html)
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!
@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?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.