Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: php include - above root directory

  1. #1
    tillabong is offline x10Hosting Member
    Join Date
    Jun 2009
    Posts
    60

    php include - above root directory

    if i want to include a sensitive file like a database login, where should i place the file when i upload to x10hosting server? if my root directory is public_html/www.mywebsite.com do i place it at public_html/databaselogin folder? and how do i link to that file using php include?

    thank you very much.

  2. #2
    vishal's Avatar
    vishal is offline -::-X10 Guru-::-
    Join Date
    Nov 2009
    Location
    INDIA
    Posts
    5,254

    Re: php include - above root directory

    u can use any folder inside public_html or there itself
    U can use include function in any php file to link it
    For eg
    <?php
    include("includes/connection.php") // includes is the folder where connection.php is located
    ?>
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

  3. #3
    tillabong is offline x10Hosting Member
    Join Date
    Jun 2009
    Posts
    60

    Re: php include - above root directory

    but the php include function only allows me to include files that are in my root folder which in this case is public_html/www.mysite.com. i want to store my database login above the root folderlike public_html/databaselogin for security purposes.

  4. #4
    vishal's Avatar
    vishal is offline -::-X10 Guru-::-
    Join Date
    Nov 2009
    Location
    INDIA
    Posts
    5,254

    Re: php include - above root directory

    U mean outside the root folder i e.(www.mysite.com -root) and u wanna place databaselogin in public_htnl or wht
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

  5. #5
    tillabong is offline x10Hosting Member
    Join Date
    Jun 2009
    Posts
    60

    Re: php include - above root directory

    yes i would like to place the file outside the root folder. and use php include to put it on my site.

  6. #6
    vishal's Avatar
    vishal is offline -::-X10 Guru-::-
    Join Date
    Nov 2009
    Location
    INDIA
    Posts
    5,254

    Re: php include - above root directory

    Since the database login is in the root folder u should use
    <?php
    include("databaselogin.php") // since in root folder no path is req
    ?>
    try this this must solve ur problem
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

  7. #7
    tillabong is offline x10Hosting Member
    Join Date
    Jun 2009
    Posts
    60

    Re: php include - above root directory

    my root folder is public_html/mysite.com. the database login file is in public_html/databaselogin folder which is outside the root folder. so the php include you wrote wont work.

  8. #8
    vishal's Avatar
    vishal is offline -::-X10 Guru-::-
    Join Date
    Nov 2009
    Location
    INDIA
    Posts
    5,254

    Re: php include - above root directory

    Try referring absolute path....
    Is this a addon domain.
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

  9. #9
    tillabong is offline x10Hosting Member
    Join Date
    Jun 2009
    Posts
    60

    Re: php include - above root directory

    ok i figured it out myself already. thanks anyway ;).

  10. #10
    marshian's Avatar
    marshian is offline x10 Elder
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: php include - above root directory

    I lol'd :p

    If you want to "secure" a script, don't put it in public_html at all, you can put it even higher than that. (eg. make a directory nonpublic_html)
    As vishal2 (finally) noticed in the end, you can use absolute paths ("/home/username/public_html/script.php" for example), or perhaps easier: relative paths can do this too.
    To refer to the directory above the one you're currently in, use "..".

    So, if you have a script in public_html/site.com and want to refer from there to a script public_html/nonpublic/script.php, you can use
    PHP Code:
    include "../nonpublic/script.php"
    Edit: sorry, too late
    Last edited by marshian; 01-10-2010 at 06:18 AM.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

Page 1 of 3 123 LastLast

Similar Threads

  1. Help With php include
    By evil-bunny in forum Scripts, 3rd Party Apps, and Programming
    Replies: 4
    Last Post: 04-27-2009, 11:10 AM
  2. Problem with root directory
    By suhaib in forum Scripts, 3rd Party Apps, and Programming
    Replies: 3
    Last Post: 06-08-2008, 12:46 AM
  3. include php within javascript
    By thezone1 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 5
    Last Post: 04-24-2008, 12:50 PM
  4. Cant installed in my root directory
    By mhine in forum Free Hosting
    Replies: 4
    Last Post: 04-11-2008, 07:19 PM
  5. Replies: 3
    Last Post: 03-10-2008, 11:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers