Jump to content

Root relative path using $_Server help


bugzy

Recommended Posts

Ok I'm using a universal header and I'm having a problem calling files on different levels.

 

I have read so many articles for hours now and it's pointing that the only way to do it in php is to use $_Server.

 

I have this on my header

 

<link rel="stylesheet" type="text/css" href=stylesheet/public.css media="screen" />

 

and I want to use that stylesheet/public.css on all files from different folders/levels.

 

 

How will I able to use $_server to call that css file w/out using the absolute path?

 

Link to comment
Share on other sites

I was able to get it using this..

 

$path = $_SERVER['DOCUMENT_ROOT'] . 'back/stylesheet/public.css';

 

thoug when I tried using it

 

<link rel="stylesheet" type="text/css" href="<?php $path; ?>" media="screen" />

 

 

tried to echo it and it gives me

 

C:/wamp/www/back/stylesheet/public.css

 

the corrent path should be..

 

http://localhost/back/stylesheet/public.css

 

 

it's not working... anyone?

Link to comment
Share on other sites

You said in your other thread there is one css file, and it's in a directory off the root. Since the client has to request the css from the server, it makes perfect sense to do it that way since that is always a valid location.

Link to comment
Share on other sites

You said in your other thread there is one css file, and it's in a directory off the root. Since the client has to request the css from the server, it makes perfect sense to do it that way since that is always a valid location.

 

Ok. Just one question..

 

Will

 

$path = $_SERVER['DOCUMENT_ROOT'] . 'back/stylesheet/public.css';

 

translate to "http://www.yourdomain.com/path_to_your/stylesheet.css"

 

on the actual server online??

 

I can't test it on my local machine because it's giving me C://...... intead of localhost/.....

Link to comment
Share on other sites

Your getting the C:// . . . because $_SERVER['DOCUMENT_ROOT'] holds the filesystem path, from the root of the filesystem. A client can not request a file based on the server's filesystem path. You may be looking for $_SERVER['SERVER_NAME']. Echo it and see what it holds . . .

 

All of the values that may be found in the $_SERVER superglobal can be found here: http://us2.php.net/manual/en/reserved.variables.server.php

Link to comment
Share on other sites

Your getting the C:// . . . because $_SERVER['DOCUMENT_ROOT'] holds the filesystem path, from the root of the filesystem. A client can not request a file based on the server's filesystem path. You may be looking for $_SERVER['SERVER_NAME']. Echo it and see what it holds . . .

 

All of the values that may be found in the $_SERVER superglobal can be found here: http://us2.php.net/manual/en/reserved.variables.server.php

 

Thanks pikachu.. Just one last qustion...

 

$_SERVER['SERVER_NAME'] will translate to "www.mywebsite.com" and not the public_home root on the actual online server am I right?

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.