homepage Welcome to WebmasterWorld Guest from 54.167.174.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Base URL - best standard possible
whatson

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4499233 posted 8:45 am on Sep 24, 2012 (gmt 0)

How do you keep the base url when you go into directories, and then all the css and images suddenly have the wrong path.
I don't want to have to write the domain name each time, I want to keep it as a variable. How is this done usually?

 

topr8

WebmasterWorld Senior Member topr8 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4499233 posted 11:42 am on Sep 24, 2012 (gmt 0)

personally i just use absolute paths for all images and css files at all times, it makes it easy:

/images/stuff/example.jpg
/css/example.css

makes it all so much simpler.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4499233 posted 2:45 pm on Sep 24, 2012 (gmt 0)

Include full path, beginning with leading slash, on all internal links to pages and resources.

swa66

WebmasterWorld Senior Member swa66 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4499233 posted 3:44 pm on Sep 24, 2012 (gmt 0)

I'd reference most "static" images etc. with an absolute path as well.

Yet, there are instances where a script needs to know a bit more about where it is being called/included:

The $_SERVER array contains a number of variables that are useful to determine the location of a php script.

$_SERVER['REQUEST_URI'] is probably the one you can work from, but there are many others, print out $_SERVER to get a better idea.

ref: [php.net...]

henry0

WebmasterWorld Senior Member henry0 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4499233 posted 4:10 pm on Sep 24, 2012 (gmt 0)

You could create a config file that will be included by the site header.

using DEFINE create a name and a location for your root
like DIR_BASE or DIR_ROOT
then with a concat define your location to be always accessible such as your CSS and IMG

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved