Jump to content

Recommended Posts

A debate with who? Please keep posts relevant to the information provided and the issue at hand. Nothing about my comment you've quoted has anything to do with the text below it.

 

Using something generic like ROOT is a bad idea, because it makes your code harder to recycle. Naming it something like loginscript_ROOT is probably better because there's less of a chance of accidentally reusing that exact name. You also know exactly WHAT 'root' you're talking about when you're using it.

 

When we're talking about web/document root, file system root, or script root, there's not really a debate. Those aren't naming 'conventions.' They are adjectives used to describe which ROOT we're talking about. Root simply means the top of a folder tree - this is why we use adjectives to help us understand where this folder tree begins.

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291354
Share on other sites

A debate with who? Please keep posts relevant to the information provided and the issue at hand. Nothing about my comment you've quoted has anything to do with the text below it.

 

What are you talking about?!

 

There are multiple people in this thread.  It is not just about you and your comments...  I am responding to the entire conversation.

 

 

Using something generic like ROOT is a bad idea, because it makes your code harder to recycle. Naming it something like loginscript_ROOT is probably better because there's less of a chance of accidentally reusing that exact name. You also know exactly WHAT 'root' you're talking about when you're using it.

 

Valid points, except there is one config file for one website in one development area and one production area, so things would never get confused.  (My "config" file isn't something that 20 websites use, like maybe is true for you.)

 

 

 

When we're talking about web/document root, file system root, or script root, there's not really a debate. Those aren't naming 'conventions.' They are adjectives used to describe which ROOT we're talking about. Root simply means the top of a folder tree - this is why we use adjectives to help us understand where this folder tree begins.

 

So what is the difference between a "Web Root" vs. "Document Root" vs. "File System Root" vs. "Script Root" in what I described above?

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291359
Share on other sites

So what is the difference between a "Web Root" vs. "Document Root" vs. "File System Root" vs. "Script Root" in what I described above?

 

Web Root and Document Root are the same thing generally.  They refer to the location from which your website is served by your webserver.  Any file/directory below the web root has a corresponding URL from which it can be accessed.

 

Filesystem root is where your filesystem on your hard drive begins.  Such as C:\ on windows, or '/' on linux/unix/mac.

 

Script Root could be whatever you want it to be, it doesn't really have any particular meaning.

 

-----

 

You can define however many "root" directories as you want, just so long as you know what each one is referencing. That is why they are usually prefixed with some other word and not just 'root'.  I usually define an includes root, uploads root, templates root, etc:

define('DOCUMENT_ROOT',		dirname(dirname(__FILE__)));
define('TEMPLATE_ROOT',		DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'templates');
define('INCLUDE_ROOT',		DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'includes');
define('UPLOADS_ROOT',		DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'Uploads');

 

What you just have to know and understand is that regardless of whether you define your own roots or not will have no effect on how a path is resolved unless you use those root constants in your paths.

 

<?php require('/file.php'); ?>

The / there will always refer to the filesystem root.  If you want to use a different root, you have to prefix the path with the appropriate root constant:

<?php require(INCLUDE_ROOT.'/file.php'); ?>

 

Likewise in HTML. 

<a href="/index.php"></a>

 

Will always refer to the web/document root.  If you wanted some other root you would have to echo it out as a prefix.

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291413
Share on other sites

I think you nailed it, kicken!  8)  (And in a polite manner too?!)  ;)

 

 

So what is the difference between a "Web Root" vs. "Document Root" vs. "File System Root" vs. "Script Root" in what I described above?

 

Web Root and Document Root are the same thing generally.  They refer to the location from which your website is served by your webserver.

 

So a "Web Root" or "Document Root" is where my files (e.g. .html, .php, etc) physically reside, correct?

 

And it sounds like "Web Root" or "Document Root" would be one of these two for me...

 

'/Users/user1/Documents/DEV/++htdocs/03_MySite/' (Dev)

'/var/www/vhosts/MySite.com/httpdocs/' (Production)

 

Right?  (Because that is where MAMP and Apache, respectively, find my physical files.)

 

 

Any file/directory below the web root has a corresponding URL from which it can be accessed.

 

"Below" means "inside of", right?  (Like "index.php" and "articles" are inside of my "Web Root"?)

 

 

Filesystem root is where your filesystem on your hard drive begins.  Such as C:\ on windows, or '/' on linux/unix/mac.

 

Okay.

 

 

Script Root could be whatever you want it to be, it doesn't really have any particular meaning.

 

I didn't follow what others were saying above as to when, where, or why I would need to reference "Script Root"?!  (It sounds like my "Web/Document Root" is also my "Script Root"...)

 

 

You can define however many "root" directories as you want, just so long as you know what each one is referencing. That is why they are usually prefixed with some other word and not just 'root'.  I usually define an includes root, uploads root, templates root, etc:

define('DOCUMENT_ROOT',		dirname(dirname(__FILE__)));
define('TEMPLATE_ROOT',		DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'templates');
define('INCLUDE_ROOT',		DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'includes');
define('UPLOADS_ROOT',		DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'Uploads');

 

What you just have to know and understand is that regardless of whether you define your own roots or not will have no effect on how a path is resolved unless you use those root constants in your paths.

 

<?php require('/file.php'); ?>

The / there will always refer to the filesystem root.  If you want to use a different root, you have to prefix the path with the appropriate root constant:

<?php require(INCLUDE_ROOT.'/file.php'); ?>

 

Okay, so in my former code, I would do this...

<!-- Include BODY HEADER -->
<?php	require_once(ROOT . 'components/body_header.inc.php');	?>

 

where "ROOT" is defined as either...

define('ROOT', ENVIRONMENT === 'development'
		? '/Users/user1/Documents/DEV/++htdocs/03_MySite/'
		: '/var/www/vhosts/MySite.com/httpdocs/');

 

 

Likewise in HTML. 

<a href="/index.php"></a>

 

Will always refer to the web/document root.  If you wanted some other root you would have to echo it out as a prefix.

 

 

Here is a key thing that I keep missing in everyone's comments...

 

What do you call either of these...

'http://local.dev3/'

'http://www.MySite.com/');

 

Above you said that the "Web Root" and "Document Root" describe where my files physically reside.

 

So what are these URLs/Paths called?

 

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291420
Share on other sites

What do you call either of these...[/b]

'http://local.dev3/'

'http://www.MySite.com/');

 

Above you said that the "Web Root" and "Document Root" describe where my files physically reside.

 

So what are these URLs/Paths called?

 

I suppose you could call them the URL Root, though I'm not aware of any particular name for them.  Generally you don't have to worry about them too much.

 

If you have a link, such as

<a href="/index.php">Home<a>

 

And you access the page from say http://local.dev3/somedir/somefile.php  then your browser will take that link URL and generate the url http://local.dev3/index.php

If you accessed the page from http://www.mysite.com/somdir/somefile.php then your browser would generate the URL http://www.mysite.com/index.php

 

It will automatically use whatever protocol (http vs https) and domain (www.mysite.com vs local.dev3) that you used when you requested the page containing the link.

 

You almost never have to include that information in your links (and probably shouldn't generally) unless you need to force a particular protocol or domain name.  Like you might use a full absolute url in a <form action=""> tag to send the user to a https url instead of a http url.

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291422
Share on other sites

Good explanation kicken, just a quick side note,

It will automatically use whatever protocol (http vs https) and domain (www.mysite.com vs local.dev3) that you used when you requested the page containing the link.

 

You almost never have to include that information in your links (and probably shouldn't generally) unless you need to force a particular protocol or domain name.  Like you might use a full absolute url in a <form action=""> tag to send the user to a https url instead of a http url.

 

However, do note that src objects (such as for image tags, script tags, style tags, etc.) will need to include the correct protocol when you're using an absolute URL. You can get around this by prefixing your URL with // instead of http:// or https:// as seen below:

<script src="//domain.com/file.foo">

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291434
Share on other sites

Using something generic like ROOT is a bad idea, because it makes your code harder to recycle. Naming it something like loginscript_ROOT is probably better because there's less of a chance of accidentally reusing that exact name. You also know exactly WHAT 'root' you're talking about when you're using it.

 

Valid points, except there is one config file for one website in one development area and one production area, so things would never get confused.  (My "config" file isn't something that 20 websites use, like maybe is true for you.)

 

Why ask for advice if you already know you're right?

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291439
Share on other sites

Using something generic like ROOT is a bad idea, because it makes your code harder to recycle. Naming it something like loginscript_ROOT is probably better because there's less of a chance of accidentally reusing that exact name. You also know exactly WHAT 'root' you're talking about when you're using it.

 

Valid points, except there is one config file for one website in one development area and one production area, so things would never get confused.  (My "config" file isn't something that 20 websites use, like maybe is true for you.)

 

Why ask for advice if you already know you're right?

 

You have an attitude problem.

 

If you can't be pleasant them post somewhere else...

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291441
Share on other sites

What do you call either of these...[/b]

'http://local.dev3/'

'http://www.MySite.com/');

 

Above you said that the "Web Root" and "Document Root" describe where my files physically reside.

 

So what are these URLs/Paths called?

 

I suppose you could call them the URL Root, though I'm not aware of any particular name for them.  Generally you don't have to worry about them too much.

 

How about the ServerName or HostName?

 

That is what my tutorial on setting up my Virtual Hosts implied...

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291444
Share on other sites

How about the ServerName or HostName?

 

The terms hostname/servername typically are used to refer to the domain name.  The http: part is the protocol or scheme.

 

http://www.example.com/somepath/somefile.php

 

http = Protocol / Scheme.  http, https, ftp, etc

www.example.com = Host name / Domain name / Server name

/somepath/somefile.php = Path

 

I am not aware of any specific term that is commonly used for the combination of the protocol and hostname.  If I had to create a variable for it I would probably name it BASE_URL or similar.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291446
Share on other sites

kicken,

 

So if I re-labeled my "Config" file, would the following be consistent with what you've been talking about...

 

 


<?php
define('ENVIRONMENT', 'development');
//define('ENVIRONMENT', 'production');

// Web Root/Document Root 
define('WEB_ROOT', ENVIRONMENT === 'development'
				? '/Users/user1/Documents/DEV/++htdocs/03_MySite/'
				: '/var/www/vhosts/MySite.com/httpdocs/');

// Base URL
define('BASE_URL', ENVIRONMENT === 'development'
				? 'http://local.dev3/'
				: 'http://www.MySite.com/');

// Secure Base URL
define('SECURE_BASE_URL', ENVIRONMENT === 'development'
				? 'http://local.dev3/'
				: 'https://www.MySite.com/');
?>

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291452
Share on other sites

Using something generic like ROOT is a bad idea, because it makes your code harder to recycle. Naming it something like loginscript_ROOT is probably better because there's less of a chance of accidentally reusing that exact name. You also know exactly WHAT 'root' you're talking about when you're using it.

 

Valid points, except there is one config file for one website in one development area and one production area, so things would never get confused.  (My "config" file isn't something that 20 websites use, like maybe is true for you.)

 

Why ask for advice if you already know you're right?

 

You have an attitude problem.

 

If you can't be pleasant them post somewhere else...

 

 

Volunteer staff and members are helping you out of their own precious free time, no one here HAS to help you. A little respect goes a long way.

 

Anyway after having my mind explode by the time I had read up to page 2.......

 

You could use this:

	define('BASEPATH', array_pop(explode(DIRECTORY_SEPARATOR,realpath(dirname(__FILE__)))));

echo BASEPATH;

place that in your top level index.php file.

 

So with this...

05_Debbie
components
	body_footer.inc.php
	body_header.inc.php

css
	_layout.css
	_main.css
	components.css
	top_menu.css

index.php // goes in here

pages
	article_index.php
	howto_index.php

BASEPATH would hold the value '05_Debbie'

 

You can include files like so...

// include body_footer.inc.php from article_index.php
include_once(BASEPATH . '/body_footer.inc.php');

// include body_header.inc.php from howto_index.php
include_once(BASEPATH . '/body_header.inc.php');

// etc etc

 

May need to be tweaked depending on your setup.

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291492
Share on other sites

That works fine too, it's really just a matter of preference.

 

I like my slightly less fancy, more manual solution for now.  (It helps keep me "honest" and make sure I know where things are going!)

 

But I like how you used PHP functions to do the work for me.

 

Some day when I become a more seasoned PHP person, then I'll likely switch over.

 

However, but to the spirit of my original question...

 

Should I be using my "Config" file with my PHP Includes, or should I *just* be using Relative Path references as some have said?

 

I suppose if I have a simple site structure, things don't change too much, and I don't have too many layers, then typing...

<?php	require_once('../components/content_sticky.inc.php');	?>

 

...isn't that big of a deal?!

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291504
Share on other sites

Should I be using my "Config" file with my PHP Includes, or should I *just* be using Relative Path references as some have said?

 

I suppose if I have a simple site structure, things don't change too much, and I don't have too many layers, then typing...

<?php	require_once('../components/content_sticky.inc.php');	?>

 

...isn't that big of a deal?!

 

Shouldn't really have config.php with a heap of includes in it(if that's what you mean?), a config file is usually for variables, arrays or constants that are used in various parts of the website such as database connection details.

 

Relative path references is the way to go, and if you're worried about having to copy/paste includes into multiple files(that's what I think you're talking about?), then you may want to develop some kind of template system.

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291506
Share on other sites

Should I be using my "Config" file with my PHP Includes, or should I *just* be using Relative Path references as some have said?

 

Shouldn't really have config.php with a heap of includes in it(if that's what you mean?), a config file is usually for variables, arrays or constants that are used in various parts of the website such as database connection details.

 

My "config" file is the one in Reply #35...

<?php
define('ENVIRONMENT', 'development');
//define('ENVIRONMENT', 'production');

// Web Root/Document Root 
define('WEB_ROOT', ENVIRONMENT === 'development'
				? '/Users/user1/Documents/DEV/++htdocs/03_MySite/'
				: '/var/www/vhosts/MySite.com/httpdocs/');

// Base URL
define('BASE_URL', ENVIRONMENT === 'development'
				? 'http://local.dev3/'
				: 'http://www.MySite.com/');

// Secure Base URL
define('SECURE_BASE_URL', ENVIRONMENT === 'development'
				? 'http://local.dev3/'
				: 'https://www.MySite.com/');
?>

 

 

Ummm.... see your own Reply #37...

You can include files like so...

// include body_footer.inc.php from article_index.php
include_once(BASEPATH . '/body_footer.inc.php');

// include body_header.inc.php from howto_index.php
include_once(BASEPATH . '/body_header.inc.php');

// etc etc

 

So your "BASEPATH" would be my "WEB_ROOT" above.

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/251803-paths-issue/page/2/#findComment-1291510
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.