Loading...


bookmark - Php Include Root Ref whats the root?

Php Include Root Ref - whats the root?

 
 Discussion by Lozbo with 6 Replies.
 Last Update: May 21, 2008, 12:43 pm
 
bookmark - Php Include Root Ref whats the root?  
Quickly Post to Php Include Root Ref whats the root? w/o signup Share Info about Php Include Root Ref whats the root? using Facebook, Twitter etc. email your friend about Php Include Root Ref whats the root? Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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.






   Tue Sep 20, 2005    Reply         

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:

CODE


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







   Tue Sep 20, 2005    Reply         

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:)

   Wed Sep 21, 2005    Reply         


Well the "www" thing is the folder name that Cpanel uses to determine publiclpy available .php and .html files and stuff

Another thing to watch out for is hard coding your username but that isnt really a major problem

I 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

   Wed Sep 21, 2005    Reply         

QUOTE (Lozbo)

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:)



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

CODE


<?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

   Wed Sep 21, 2005    Reply         

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.

   Thu Sep 22, 2005    Reply         


Thanks
Php Include Root Ref

Genius! Thank you for that Spectre, saved me a LOT of hassle!

-reply by Pete

   Wed May 21, 2008    Reply         

Quickly Post to Php Include Root Ref whats the root? w/o signup Share Info about Php Include Root Ref whats the root? using Facebook, Twitter etc. email your friend about Php Include Root Ref whats the root? Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Include File.php?id=something

Well, I am making a full CMS system for my site, and want to make the index.php file to include the view.php?id=1 file. I tried with this code, but it didn't work: CODE<?php include 'view.php?id=1' ?> This is the error I get:CODEWarning: main( ...more

   29-Jan-2006    Reply         

Installing Phpmyadmin On Local Mach...

I am going to show to all members (beginning developers ) how to install phpMyAdmin on Windows local machine. First of all.. For those who doesn't know what is phpMyAdmin ...more

   20-Jan-2009    Reply         

To Deploy Php Application Outside H...

Hi All, I am developing one web application in PHP.How can i deploy the application outside the htdocs folder.When using the IIS in ASP.Net,we can make the folder in any drive as the root folder for the particular application.How can i do this in PHP??... Regards, Tinoy Mala ...more

   13-Apr-2011    Reply         

Debug The Php Code    Debug The Php Code (4) (1) Cleaning User Input With Regex   Cleaning User Input With Regex