Jump to content

Problem with permissions?


tiby312

Recommended Posts

I think this is the right place to post this. I am trying to build a website. There are many pages on this website. They all use the same css files etc, so I thought I'd use this 'include' thing I learned at w3cschools to make it easier to change things. So every page has this for the <head>

<head>
<title>Main</title>
<?php include($_SERVER['DOCUMENT_ROOT'] . "/php/head.php"); ?>	
</head>

I have tried to make everything relative to where the server directory is incase I move it or something. The head.php file looks like this:

<?php $b=$_SERVER['DOCUMENT_ROOT']."/" ?>
<base href="<?php echo $b ?>"/>
<?php

chmod($b."css/website_style.css",0755);
chmod($b."css/menu_style.css",0755);
chmod($b."css/button_style.css",0755);
chmod($b."js/jquery.js",0755);
?>
<link rel="stylesheet" type="text/css" href="css/website_style.css" />
<link rel="stylesheet" type="text/css" href="css/menu_style.css" />
<link rel="stylesheet" type="text/css" href="css/button_style.css" />
<script type="text/javascript" src="js/jquery.js"></script>

But this does not work. When I look at the error console in google chrome, it says "Not allowed to load local resource." I have no clue why it is not working and have no idea where to look for answers. I found this thing called chmod which sounded like what I needed so I tried putting that in, but it didn't fix anything. If someone could but point me in the right direction that'd be very helpful thank you! I am using xampp on windows 7 64bit.

 

Link to comment
Share on other sites

The error is probably being caused by your <base> tag.  $_SERVER['DOCUMENT_ROOT'] returns a local path on the server. The <base> node is supposed to use a standard URL. Remove the <base> tag (or fix it to be your sites URL root, i.e. http://www.domain.com) and get rid of the chmod stuff and you should be about right. The only other problem you are likely to run into is '404 Page Not Found' for the <link> and <script> tags. The paths used for the href/src are relative, this can often cause problems when working with files that aren't in the root folder. You can fix that by simply adding a forward slash to the start of the path, thus making it relative to root.

Link to comment
Share on other sites

Jesus it was so simple. All I had to do was put a "/" in front of it. Thank you so much! I didn't think the html code of pages that were not in the root directory would know where the root was without telling it directly using the <base> tag, hence me going crazy with it.

 

It does seem odd to me, though, that this code doesn't work also then.

<?php include("/php/head.php"); ?>	

Link to comment
Share on other sites

It's not odd, I'll try to explain.

 

The include is done on the server side, so the PHP 'engine' will need to know it's local path, i.e. where it is stored on the server. PHP will essentially then treat them as though the information in the included file is within the original file. Files can be include from outside the DOCUMENT_ROOT path and / therefore refers to the root of the drive (well in linux at least).

 

The paths in the <link href ... > and <script src ... > are actually evaluated on the client side, so they need to know the URL address of the files to request them. Individual HTTP requests are then made for each resource. A HTTP request cannot be made for a file outside of DOCUMENT_ROOT, therefore it knows that the root i.e. /, represents DOCUMENT_ROOT.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.