Jul 24, 2008

Php Include Root Ref - whats the root?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Php Include Root Ref - whats the root?

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

Reply

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

Reply

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

Reply

dogomchawi
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

Reply

cragllo
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

 

 

 


Reply

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

Reply

iGuest
Thanks
Php Include Root Ref

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

-reply by Pete

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php, include, root, ref, whats, root

  1. Can Some One Tell Me Whats Wrong With This
    (2)
  2. Whats Wrong>?
    please see this piece of code and see whats wrong: (9)
    CODE require('connection2.php'); $select=mysql_query("SELECT * from
    `users` WHERE password='$_GET[password]'");
    $co=mysql_num_rows($select); if ($co = 1) {
    session_start(); $s=session_id();
    $_SESSION['access']="yes";
    $username=$_GET['username'];
    header("location:../main/index2.php?a=$_GET[username]&s=$s"
    ;); //echo "<a href='.&....
  3. Whats The Beg Thing About Php?
    help (7)
    um, I'm just now begining PHP and my SQL and I've read a book about them. But I was
    wondering, I hear JSP is even better, harder, but better. If you have some good reasons about why
    this language is so good, do tell. Thanx.....
  4. [question] Php / Jsp ?
    What's the difference between PHP & JSP? (0)
    Since my next project in my school will start soon, students in my course have been allowed to
    choose between PHP and JSP to create a simple e-commerce website. I would like to ask the
    differences between the two languages. Which of them would be better for creating such a site?
    What's the main differences between the two languages? Thanks for your help.....
  5. What's A Good Open Source That Has...
    (1)
    good emoticons? i wanna allow users on my message boards to post them, but i also don't wanna
    steal any images without permission... good links, anyone? thanks in advance!....
  6. What's The Best Place To Learn Php?
    help a newb get started (11)
    I've never touched PHP or MySQL before /unsure.gif' border='0' style='vertical-align:middle'
    alt='unsure.gif' /> . My experience is regular HTML and CSS. Could someone please link me to a
    site with a good, easy, free online tutorial for a newb like me? Thanx much in advance!
    /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  7. Mysql Errors
    cant find whats wrong :( (3)
    I am working on my guestbook, better to say I am transfuring it from old to new site, but I got some
    errors now I did not had at my old hoster and I cannot figure out whats wrong: CODE
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
    /home/pbrugge/public_html/guest.php on line 104 Warning: mysql_fetch_array():
    supplied argument is not a valid MySQL result resource in /home/pbrugge/public_html/guest.php on
    line 110 This is the complete relevant code perhaps I overlooked something but I keep ove....

    1. Looking for php, include, root, ref, whats, root

Searching Video's for php, include, root, ref, whats, root
advertisement



Php Include Root Ref - whats the root?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE