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
https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/
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?

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.

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/.....

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.