bugzy Posted July 9, 2012 Share Posted July 9, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/ Share on other sites More sharing options...
bugzy Posted July 9, 2012 Author Share Posted July 9, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360405 Share on other sites More sharing options...
Pikachu2000 Posted July 9, 2012 Share Posted July 9, 2012 href="http://www.yourdomain.com/path_to_your/stylesheet.css" Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360430 Share on other sites More sharing options...
bugzy Posted July 9, 2012 Author Share Posted July 9, 2012 href="http://www.yourdomain.com/path_to_your/stylesheet.css" Pikachu2000 It's an absolute relative path.. as much as possible I don't want to use it.. Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360431 Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2012 Share Posted July 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360435 Share on other sites More sharing options...
bugzy Posted July 10, 2012 Author Share Posted July 10, 2012 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/..... Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360436 Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2012 Share Posted July 10, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360438 Share on other sites More sharing options...
bugzy Posted July 10, 2012 Author Share Posted July 10, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360439 Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2012 Share Posted July 10, 2012 IIRC, it depends on the server's configuration, but I can't test that right now . . . Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360440 Share on other sites More sharing options...
bugzy Posted July 10, 2012 Author Share Posted July 10, 2012 IIRC, it depends on the server's configuration, but I can't test that right now . . . Thanks you! I'll just test it myself then once I got my test server back again. Quote Link to comment https://forums.phpfreaks.com/topic/265451-root-relative-path-using-_server-help/#findComment-1360442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.