Jump to content
xisto Community
Lozbo

Php Include Root Ref whats the root?

Recommended Posts

Every one knows that we can include files in our site, so we have a folder with 2 files, an index.php with a menu.php included. But they are on the same folder, what if we wanted to make a relative reference for it, so we will always put include("/files/menu.php") and it will always work wherever that file is (the file calling the include).Ive had troubles with this, as it doesnt seem to be working, i have to change to the dot notation (like ../../../../../files/menu.php) in order to keep my includes right. Does any one know what the root is for the include or how can i make a root that always answer to the slash (" / ") location?Hope i made my self clear.

Share this post


Link to post
Share on other sites

Hmm, I'm not sure why you can't relatively call other files like that. All I know if that if you want to do call from another folder, you will have to do this:

 

<?php  include("include("/home/cpanel login username/www/folder/another folder/filename");?>

Replace cpanel login username with the username you use to login to cpanel. Replace folder and another folder with actual folder names. filename is the name of the file you are calling in a folder (another folder in this case).

 

Hope that helps.

Share this post


Link to post
Share on other sites

And what if i have a web where cpanel is not at use? should it be the ftp account? What if its a linux server? What does www mean, will it go to the actual root folder of the web server? Thanks anyway, have not tried but gonna take a look. Thanks:)

Share this post


Link to post
Share on other sites

Well the "www" thing is the folder name that Cpanel uses to determine publiclpy available .php and .html files and stuffAnother thing to watch out for is hard coding your username but that isnt really a major problemI have never had to code anything past the "../filename.php" becuase i use a hierarchy structure. With this host I am not sure yet (havnet got an account) but there should be a folder level somewhere that contains the "www" folder - I have always used the superfolder to hold all the other stuff that i want to keep private from the public but accessable to other files later on. that way all you need is the "../" to get to the root folder past the "www" folder.Dunno if that will help but it might come in handy later on in your coding expiriences =)GL

Share this post


Link to post
Share on other sites

And what if i have a web where cpanel is not at use? should it be the ftp account? What if its a linux server? What does www mean, will it go to the actual root folder of the web server? Thanks anyway, have not tried but gonna take a look. Thanks:)

188001[/snapback]


WOW dude... cPanel is just one of many web hosting control panels out there, they dont effect teh way php runs! Most web servers are linux, www simpkly means default for those with multiple servers...

as snlildude87 said

<?php include("include("/home/cpanel login username/public_html/");?>
php knows that taht means the root folder, for each host this may be different, this is the standard directory structure for cPanel, Plesk is different, for a windows server, it will be like windows is C:/Apache/hosted/user/htdocs/ something liek that

Share this post


Link to post
Share on other sites

The $_SERVER variable always contains an index 'DOCUMENT_ROOT' which points to the document root of your site from the top-level directory. So using include($_SERVER['DOCUMENT_ROOT'] . '/folder/file.php'); may help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.