Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: php include - above root directory

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

    Smile Re: php include - above root directory

    marshian u made an important point...... good i support u
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

  2. #12
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: php include - above root directory

    If you want to make things really simple, put an init.php in ~/public_html and include it with a include_once($_SERVER['DOCUMENT_ROOT'] . '/init.php'). Within init.php, add top-level include paths:
    PHP Code:
    // add ~/include/php and doc root to include path
    set_include_path(get_include_path() 
            . 
    PATH_SEPARATOR dirname($_SERVER['DOCUMENT_ROOT']) . '/include/php'
            
    PATH_SEPARATOR $_SERVER['DOCUMENT_ROOT']); 
    If you want to get fancy, define a function to append to the include path:
    PHP Code:
     function addToIncludePath($path) {
        
    $currIncPath get_include_path();
        if (!
    preg_match('#(^|' PATH_SEPARATOR ')'.preg_quote($path'#').'(' PATH_SEPARATOR '|$)#'$currIncPath)) {
            
    set_include_path($currIncPath PATH_SEPARATOR $path);
        }

    If you're on paid hosting, you can set auto_prepend_file (with php_value in .htaccess) to make this even easier, including init.php implicitly. At that point you can set include_path directly, but doing it in init.php means it's auto-configuring; you don't need to have a different configuration for your development and live servers.
    Last edited by misson; 01-10-2010 at 07:24 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Jon Skeet's and Eric Raymond's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

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

    Re: php include - above root directory

    Really helpfull misson, thks for the info
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

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

    Re: php include - above root directory

    thanks for all the help. but how do you include a file that is not under /home/user/public_html. lets says i put it in /home/user/databse folder.how do i use php include to direct the file there?

    if my root folder is /home/user/public_html/mysite.com and i put my database log in file above my root site but still under public_html folder. why wont it be safe? cause my root directory is still /home/user/public_html/mysite.com and people cant access files above my root directory if they access my website right?

    sorry i know thats a bit too many questions. im really new at this. hope you guys could help me out. thanks.

  5. #15
    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 relative path like inclued "/home/user/databse.php"
    If you looking for more security u will have to begin from the first.Try using relative path it nust work
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

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

    Re: php include - above root directory

    it doesnt work.

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

    Re: php include - above root directory

    Sorry, i will give a try to solve it and if i get i will post you
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

  8. #18
    Anna's Avatar
    Anna is offline I am just me
    Join Date
    Aug 2007
    Location
    Sweden
    Posts
    6,710

    Re: php include - above root directory

    I do believe that to be able to include a file not in the public_html folder (or one of its subfolders), you'll need to use absolute path.

    Should be something like: /home/cpanelusername/path/to/script/script.php
    Do you have trouble reaching your site?
    Check here first: News and Announcements


    Don't forget that x10hosting has a chat service as well. Come and join the fun
    There's a lot helpful users there if need help building your site
    Connect to our chat

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

    Re: php include - above root directory

    I just tried using relative path and it just working fine... I dont know why you ends up with error
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

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

    Re: php include - above root directory

    i created a folder home/user/Database and i put the database login file in that folder using php include.

    include_once '/home/user/Database/db_connect.php';

    and it gave this error.

    include_once(/home/user/Database/db_connect.php) [function.include-once]: failed to open stream: No such file or directory
    Last edited by tillabong; 01-13-2010 at 09:28 AM.

Page 2 of 3 FirstFirst 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