Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Accessing CSS  file located outside of server root

Posted on 2005-05-11
16
Medium Priority
?
943 Views
Last Modified: 2008-03-03
Linux HTTPD (apache).
Some experts are of the impression that access to files outside of the server root is not allowed by the (httpd) server. I have a number of PHP scripts that have no difficulty accessing a CSS file located outside of this server root through the HTML link tag and a symbolic link. The files render correctly except for the fact that I have a <BODY class="wp2"> in these scripts which doesn't render as expected, this "wp2" is defined in the CSS file and it works when used in another application.

Has anyone some experience and some hints in this respect?

Here are a few lines of code used in scripts and HTTPD
Document root in HTTPD is /home/meeting/chair
CSS file is /var/nobla/u1/h123.css
This HTML line is in every script <link rel=stylesheet type="text/css" href="h123.css">
This link is in every directory h123.css -> /var/nobla/u1/h123.css
The CSS file links class wp2 to  /var/nobla/i1/wp2.png

Thank you for your help
0
Comment
Question by:rblampain
  • 8
  • 4
  • 2
  • +2
16 Comments
 
LVL 7

Accepted Solution

by:
jdpipe earned 1500 total points
ID: 13979133
this is an interesting effect... but I wonder why you need to use the symbolic link like that? The whole point of having a 'document root' for HTTPD is that it gives you a place where you want the publicly available files to sit. Adding symlinks will of course work but it is messing up the tidiness of the directory structure.

as for the wp2 thing, I would be almost certain that this was a problem to do with your HTML or CSS, rather than a weird phenomenom of some other sort. Post your HTML  and CSS and I'll take a look.

JP
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13979148
an alternative thing you could try would be to use the Apache 'Alias' directive instead of symlinks. Perhaps that will confirm that the symlink is doing nothing strange.
JP
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13979162
or better still, use AliasMatch just ONCE, and you won't need repeated symlinks...
JP
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 32

Expert Comment

by:Batalf
ID: 13979188
If you can't access

/var/nobla/u1/h123.css

over http(i.e by an url in your browser), then you can't refer to any files there either.

If this line:

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

is from an HTML file on your document root, then it refers to

/home/meeting/chair/h123.css

(Since /home/meeting/chair is your document root.).

What you can do is to read the content of the css file and put it between a <style> and </style> tag.

example:

<?php

if(file_exists("/var/nobla/u1/h123.css")){

?>
<style type="text/css">
<?php
echo file_get_contents("/var/nobla/u1/h123.css");
?>
</style>
<?php

}

?>

0
 
LVL 32

Expert Comment

by:Batalf
ID: 13979211
sorry, didn't see the info regarding the symbolic link.

If you open the css file in your browser(http://www.yourDomain.com/h123.css), do you see the "wp2" class there?

If yes, then there's probably something wrong in your HTML code.

Batalf
0
 
LVL 1

Expert Comment

by:Codeit1978
ID: 13979381
The only problem that i have experienced is that I need to put the full path to the css file

<link rel=stylesheet type="text/css" href="http://blah.com/h123.css">

Other than that I have had no problems.
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13979691
That shouldn't be required, if it's being hosted on the same server. You're not doing anything funny with multiple <VirtualHost>s are you?
0
 
LVL 2

Expert Comment

by:Lance_Frisbee
ID: 13982448
you could also back out of directories...  "../../../../var/nobla/u1/h123.css"
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13983278
You can't back up above the document root. Apache doesn't let you. Unless I'm very much mistaken...

JP
0
 

Author Comment

by:rblampain
ID: 13984581
Thank you all for your suggestions. A few answers to your comments/questions:
 jdpipe: ......why you need to use the symbolic link like that? We have 2 applications each using their own tailored instances of HTTPD but the rendering of pages is the same, therefore we use the same CSS file.  If there is a better way, I'd welcome it. I'd prefer not to have to copy this file for the second application if possible since this means 2 files to edit instead of one.
I tried ALIAS in HTTPD conf but it doesn't work, it looks like it's designed to work at the directory level, not the file level. HTTPD is now looking for /documentroot/h123.css.
........ You're not doing anything funny with multiple <VirtualHost>s are you? Answer: NO.

Batalf: yes, the wp2 class shows as expected

 Codeit1978:  it looks  like the use of CSS you're talking about is outside of the server (httpd), The full path you recommend would be added to the document root like this: "documentrootfullpath" which would lead us nowhere.

Lance_Frisbee: this also seems to be outside the server
------------------------------------------------------------------------------------
I have 3 HTML scripts followed by a number of PHP scripts in this application, here is the first PHP script. The <body> tags in the HTML scripts do render properly using the same symlink. Only the <body> tags going through the HTTPD server do not render as intended.

Note that the class is really "wp2cpng" not "wp2" as stated earlier.

<? session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Structure File part 1a</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel=stylesheet type="text/css" href="h123.css">
</head>

<body class="wp2cpng">
<table class="tabl01"><tr><td width="100%">
<div align="center"><h2>Locate File</h2>
<?
function create_struct0() {#f0
# part 1 create array according to path - may be useless
 global $filename, $fyle, $fyle0, $aray, $cont, $ol, $li;
 $stringy=ltrim($filename, "/"); # remove first /
 $aray=explode("/",$stringy);
 $cont=count($aray);
 $_SESSION['cont'] = $cont;
 $ol="&lt;ol&gt;";
 $li="&nbsp;&nbsp;&lt;li&gt;";
 $fyle="<html><body><pre>";
 $fyle0="<html><body><pre>";
 for ($i=0; $i < $cont; $i++) {#f1
 $fyle .=  $ol . "<br>" . $li . $aray[$i] . "<br>";
 $fyle0 .= "<ol><li>" . $aray[$i];
 $ol="&nbsp;&nbsp;&nbsp;&nbsp;" . $ol;
 $li="&nbsp;&nbsp;&nbsp;&nbsp;" . $li;
 }#f1
 $_SESSION['fyle'] = $fyle;
 $_SESSION['fyle0'] = $fyle0;
 $_SESSION['ol'] = $ol;
 $_SESSION['li'] = $li;
 #echo $fyle;            #= constructed string to be saved & passed *******************
 }#f0
#
$filetype=0;
if (isset($_POST['filename']))
{#1
  ### trim it for unwanted spaces or other
  $filename=trim($_POST['filename'],"\x00..\x20");
  ### add extension to structure filename
  $filenamestruct = $filename . ".struct";
  $_SESSION['filenamestruct'] = $filenamestruct;
  ### check is full path
  if (substr($filename,0,6) != "/home/")            
     {#0            ### adjust /home/ in real life ***  
     echo "Path is incorrect <br>";                  
     break;                                          
     }#0                                            
     else                                    
        {#6
        ### check main file exists, if struct file exists or not
           if (file_exists($filename))
             {#2
             ### check type of file: plain text or html  
             $unstripped = file_get_contents($filename);
           $stripped = strip_tags($unstripped);
            if ($stripped != $unstripped) {#10
              echo 'The file has been found, it is of type HTML (it is not PLAIN TEXT)<br>';
              $filetype=1;
              }#10
              else{#11
                  echo 'The file has been found, it is of type TEXT (it is not HTML)<br>';
                      }#11
                if (file_exists($filenamestruct))
                  {
                   echo "The 'Structure File' exists for   " . $filename ."<br>";
                  ?>
                  <br><Form method = "post" action = "http://192.168.1.13/edit_files/edit.php">
                  <input type="submit" value="Click Here To Edit it"></form>
                  Or click one option in the right panel.
                 
                  <?}
                  else
                     {#4
                     echo "The 'Structure File' has to be created for <br> " . $filename . "<br><br>";
                     create_struct0();      # according to path - may be useless
                     ?>
                  <form action="struct1.htm" name="form1">
                  <input type="submit" value="If this is correct, click here to Continue">
                  </form>
                     <?
                     }#4
             }#2  
             else
                {#5
                echo "There is no such file as $filename <br>";
                break;
                }#5
        }#6
}#1
?>

<script type="text/javascript">
<!--
document.write("Last Updated: "+document.lastModified);
//-->
</script>
</td></tr></table>
</body></html>
------------------------------------------------------------------------------------
And here is the contents of the CSS file
.tabl01 {

        border : none;

        margin-left : 12px;

        margin-right : 12px;

       

        text-align : left;

        }



.tac {text-align: center;}

.cr {color: red;}

.fsi {font-style: italic;}

.cb {color: blue;}

.c5 {color: red; font-size: 200%;}

.c4 {color: red; font-size: 60%; font-style: italic;}

.c2 {color: red; font-size: 80%;}





/*dec 2003 raise a topic*/

.gr  {color: green;}

.gr1 {color: green; font-size: x-small;}

.gr2 {color: green; font-size: small;}

.rd  {color: red;}

.rd1 {color: red; font-size: x-small;}

.rd2 {color: red; font-size: small;}



.pluie {background-image: url("/var/nobla/i1/anipluie.gif"); background-attachment : fixed; }

.cloud1 { background-image: url("/var/nobla/i1/cloud1.gif");

        background-position: top left;

        background-repeat: repeat-x ;}





.yel   {background-color: yellow; text-align: center;}

.li     {background-color: lime; text-align:left;}



.left { background-image: url("/var/nobla/i1/l.gif");

        background-position: top left;

        background-repeat: repeat-y ;}



.middle { background-image: url("/var/nobla/i1/m.gif");

        background-position: top left;

        background-repeat: repeat-y ;}



.right { background-image: url("/var/nobla/i1/r.gif");

        background-position: top left;

        background-repeat: repeat-y ;}



h1,h2,h3,dt {color: green;}





a.nodec {text-decoration: none;}

        a:link {color: #0000ff;}

        a:visited {color: #ff00ff;}

        a:active {color: black;}



.hrul   {color: lime}

.frul   {border-style: solid; height: 12px; color: #ffccff;}





/*          wall papers    */

.wp1 {background-image : url("/var/nobla/i1/wp1.gif"); background-attachment : fixed; border: 0;}

.wp2 {background-image : url("/var/nobla/i1/wp2.gif"); background-attachment : fixed; border: 0;}

.wp2a {background-image : url("/var/nobla/i1/wp2a.gif"); background-attachment : fixed; border: 0;}

.wp2b {background-image : url("/var/nobla/i1/wp2b.gif"); background-attachment : fixed; border: 0;}

.wp2c {background-image : url("/var/nobla/i1/wp2c.gif"); background-attachment : fixed; border: 0;}

.wp2cpng {background-image : url("/var/nobla/i1/wp2c.png"); background-attachment : fixed; border: 0;}





/*           venetian blind          */

.ven {background-image : url("/var/nobla/i1/ven.gif"); background-attachment : fixed; border: 0;}



span.lastmodified {font-size: xx-small; background-color: silver;  margin-left : 12px; }



.lnk01 {color : Blue;}



body

{

overflow-x:hidden;             /*precaution: removes horizontal scrollbars*/

/* keep this as it works with IE */

/* ============================= */

scrollbar-face-color:#ce9c63;

scrollbar-highlight-color:#ffce9c;

scrollbar-3dlight-color:#ffce9c;

scrollbar-darkshaddow-color:#ce9c63;

scrollbar-shadow-color:#ffce9c;

scrollbar-arrow-color:#ff9c9c;

scrollbar-track-color:#ce9c63;

}

0
 

Author Comment

by:rblampain
ID: 13984610
I've forgotten to mention FRAMES are used.
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13985936
When you say you've got a 'tailored' version of HTTPD, what exactly is it that you've tailored?
JP
0
 

Author Comment

by:rblampain
ID: 13993892
The httpd.conf files have different parameters like the document root and a few others. Nothing special.
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13993947
Put that stuff up on a sample server somewhere and tell us what we *should* see and what we *actually* see, OK?

JP
0
 

Author Comment

by:rblampain
ID: 13996989
To jdpipe:
I'm not too sure of what you want put on a sample server and I probably wouldn't know how to give access to it. The original problem is just a "tiled backgound" that doesn't show as intended.  I've changed the tag from <body class=...> to <body background =...> and put a symlink to the image that should tile the background, that gives the intended result on the screen and leave only one file to edit (the image). I'm willing to leave it as it is.

I think that once there is a need to see a lot of material (as above), the issue becomes confused and people start spending too much time for little gain and I think it's not worth it in this case.

I'm quite prepared to give you the points as you've been focused on the problem and you've spent a fair bit of time on it.  Let me know if you think my view is unsatisfactory.
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13997044
Hi rblampain
Cheers for that. It's hard sometimes to tease out the crux of the problem from a big pile of code. Hope to be of more use next time.
JP
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question