Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts

    change my php include path

    how would i go about changing my default include path to the root of my site? what i want to do is when i type in
    PHP Code:
    include('some/file.php'); 
    and the page i use the script in is "dir/example/script.php" it doesn't look for "some/file.php" in "dir/example/script.php/some/file.php" it goes to the root of my site "/" then looks for "some/file.php". so it would go like this:
    root -> some/ -> file.php
    instead of:
    dir/ -> example/ -> script.php-> some/ -> file.php
    if i could get some help on this it would be great !
    ..
    ▲ ▲

  • #2
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe with $DOCUMENT_ROOT?
    so like this:
    PHP Code:
    <?php
     
    include($DOCUMENT_ROOT "/page.php");
     include(
    $DOCUMENT_ROOT "/map/page.php");
    I think you'll get the picture..
    I don't know if it's what you need but.. you can always try.
    Good luck!
    Last edited by arne2; 03-27-2007 at 04:30 PM.

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    set_include_path('/home/httpd/...');

    //include files

    restore_include_path(); 
    Or just include the file absolutely.

    PHP Code:
    include('/some/file.php'); 

  • #4
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts
    when i use
    PHP Code:
    include_once('../statistics.php'); 
    it works... but when i use
    PHP Code:
    include_once('/statistics.php'); 
    it returns these errors:
    Code:
    Warning: main(/statistics.php): failed to open stream: No such file or directory in /home/content/A/r/m/Armondo13/html/usersys/userlook.php on line 9
    
    Warning: main(): Failed opening '/statistics.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/content/A/r/m/Armondo13/html/usersys/userlook.php on line 9
    i tried changing the include path in my php.ini file with this code:
    Code:
    include_path = /usr/local/lib/php/home/content/A/r/m/Armondo13/html
    and it like...screwed up this code on my page:
    PHP Code:
    <?php
    if(isset($lookupuser)) {
    $dbcnx mysql_connect("*""*""*"); 
    mysql_select_db("flashanims_db");

    $query "SELECT * FROM users WHERE username='$lookupuser'"
         
    $result mysql_query($query) or die(mysql_error());

    while(
    $r mysql_fetch_array($result)){
         
    $usernum $r['id'];
         
    $useremail $r['email'];
         
    $userpoints $r['points'];
         
    $userjoin $r['joined'];
         
    $userrank $r['rank'];
         
    $userlastseen $r['lastseen'];
         
    $yr substr($userlastseen22);
        
    $mo substr($userlastseen52);
        
    $da substr($userlastseen82);
        
    $hr substr($userlastseen112);
        
    $min substr($userlastseen142);
        if (
    $hr "11") {
        
    $x "12";
        
    $timetype "PM";
        
    $hr $hr 12;
        }else{
        
    $timetype "AM";
        }
    }
    print 
    "Username: $lookupuser<br/>Rank: $userrank<br/>Points: $userpoints<br/>Last Seen On: $mo/$da/$yr $hr:$min<br/>User Number: $usernum<br/>Member Since: $userjoin<br/>Email: $useremail<br/>";?><br/><span>Look up a username:</span><br/>
    <form action="userlook.php">
    <input type="text" name="lookupuser" />&nbsp;<input type="submit" name="Search" />
    </form> <?php } else { ?>
    <span>not found</span>
    <?php }
    ?>
    ..
    ▲ ▲

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok let me explain this to you. You can include "relative" or "absolute" files into your pages.

    Relative means an include relative to your current location. For example lets say you are in the folder web directory where your index file is located and you do:
    PHP Code:
    include('somefile.php'); 
    That will search for that file in the same folder as your index file. "Relative to your current location.

    Now lets say you do this:
    PHP Code:
    include('/somefile.php'); 
    Notice the slash as the beginning. This tells the server to start from ground zero "/".

    So from looking at your error your index file is located here:
    /home/content/A/r/m/Armondo13/html/index.php

    So if you are in the directory /html, and you include a file relatively, it will look for that file in that directory.

    If you add the slash in front, it will basically back all the way up to the beginning of your directory tree. It will search in the same directory as "home" is located.

    Now what I showed you with the
    PHP Code:
    set_include_path('/home/...'); 
    That will basically change your "relalative" location for includes. I dont advise in using this unless you have a good reason. For example I run a server with ALOT of websites that plug into a CRM. Now since there all on the same server I can change my include path to that of the file locations for all my files in the CRM and include them relatively so they will act right as they include files within there own files... Sounds complicated but I wouldn't worry about that until you run into a situation like that.

    If you need more clarification let me know.

  • #6
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i guess that makes sense a little bit...so your saying if i use absolute it backs up all the way to my home directory or the html dir where my root is? cause that is what i want...i don't want to to go relative to the current page i'm on...i want it to go to the root of my site and then search from there.
    ..
    ▲ ▲

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by Armondo View Post
    i guess that makes sense a little bit...so your saying if i use absolute it backs up all the way to my home directory or the html dir where my root is? cause that is what i want...i don't want to to go relative to the current page i'm on...i want it to go to the root of my site and then search from there.
    Absolute means you need the full path to the file. Relative means relative to the current directory of the file.

  • #8
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I UNDERSTAND THAT. NO NEED TO USE BOLD LETTERING . what i am saying is that if i use absolute file inclusion does it search my root up, or what?
    ..
    ▲ ▲

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Yes... hence the "full path".

  • #10
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Most people use relative includes. So lets put out a document tree:

    /home/content/A/r/m/Armondo13/html/

    That is your html directory where you are uploading your files.

    if you are in this directory

    /home/content/A/r/m/Armondo13/html/usersys/config.php

    and you want to backup to yoru html directory you would do this

    include('../somfile.php');

    The dot dot backups up 1 directory and looks for the file. You can do that as much as you want.

    include('../../../somefile.php');

    Now it would look in your 'm' directory...

    Absolute means you have to provide the FULL path:

    /home/content/A/r/m/Armondo13/html/somefile.php

    Just stick with relative URL's until you get a better understanding


  •  

    Posting Permissions

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