|
|
|
|
![]() ![]() |
Sep 20 2005, 09:28 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 282 Joined: 1-September 05 From: Wanatos Member No.: 11,382 |
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. |
|
|
|
Sep 20 2005, 10:03 PM
Post
#2
|
|
|
Moderator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,325 Joined: 8-March 05 From: Mawson, Antarctica Member No.: 4,254 |
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. |
|
|
|
Sep 21 2005, 01:12 AM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 282 Joined: 1-September 05 From: Wanatos Member No.: 11,382 |
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:)
|
|
|
|
Sep 21 2005, 02:02 AM
Post
#4
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 42 Joined: 20-September 05 Member No.: 12,091 |
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 |
|
|
|
Sep 21 2005, 04:29 PM
Post
#5
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 933 Joined: 24-August 04 Member No.: 892 |
QUOTE(Lozbo @ Sep 21 2005, 01:12 AM) 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 |
|
|
|
Sep 22 2005, 05:17 AM
Post
#6
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 873 Joined: 30-July 04 Member No.: 246 |
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.
|
|
|
|
May 21 2008, 12:43 PM
Post
#7
|
|
|
Hail Caesar! ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Thanks
Php Include Root Ref Genius! Thank you for that Spectre, saved me a LOT of hassle! -reply by Pete |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 12th October 2008 - 03:52 PM |