How to tell if my content is included

5 replies
I have a file on my server I use and get file contents of that file for my other web pages. It's plain looking though if it's viewed on it's own.

I was think of reading the url to see if the file (php page) was being read on it's own then doing if statements and string replacements to add graphics and formatting.

Any other ideas to see if the file is being read as a stand alone or if it's included in content in another one of my web pages?

Thanks,

Rick
#content #included
Avatar of Unregistered
  • Profile picture of the author hometutor
    That didn't work

    url var stayed the same whether included in a different url or not


    Rick
    {{ DiscussionBoard.errors[11313766].message }}
  • Profile picture of the author hometutor
    Figured it out

    I just add ?slim at the end of the get file contents

    Rick
    {{ DiscussionBoard.errors[11313904].message }}
  • Profile picture of the author Alexis Wilke
    Do you have full access to the server? If so, it is rather simple (if you know what you're doing.)

    Now, when presented in a page and you let someone download the file, it's going to be a direct access as well. So... how do you know whether it is that direct access or a user who really directly tried to check out the document?

    As hometutor mentioned, you could add a parameter to distinguish the two. For example, in your page you could add a download parameter. When that parameter is defined, the code reacts as if a direct download was being requested. Of not present, then fallback to that other page that presents the document in a clean and explanatory manner.

    To do that with Apache, you can use the Rewrite plugin and check the path. When it matches the file, further check for the download parameter, if present, just ignore and let Apache send the document to the client. If the download parameter is missing, change the name with something like .html instead of the file extension and that .html file is what you want to show instead. The file will include a link to the item for download including the "?download" parameter.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} my_file_for_download.pdf
    RewriteCond %{QUERY_STRING} !download
    RewriteRule . /path/to/html/instead.html [last,passthrough]

    Note 1: the "download" condition starts with an exclamation mark (!) which means "not equal to";
    Note 2: the RewriteRule includes a lone period "." before the path. It's not a mistake.

    The flags may not all be correct. But it should be close enough for you to find the right formula for your situation.

    Note that these rules will also work in your .htaccess file if you have such.
    {{ DiscussionBoard.errors[11316275].message }}
Avatar of Unregistered

Trending Topics