include file path problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raheem

    include file path problem

    Hello,

    I built a development version of a live website on my hosted account.
    However the development version is having problems with finding
    include files. After troubleshooting I was able to resolve the issue
    by removing the ../ from the beginning of the include file path. But
    now I am looking at making this modification hundreds of times in all
    kinds of files. I'd like to keep the dev env similar to the live env
    so I can port changes easily. Below is an example of working and non-
    working include file definitions:

    working - include_once("d blib/db_con.php");
    non-working - include_once(". ./dblib/db_con.php");

    But I dont understand why this would work in one server and not the
    other. Is there some kind of setting in htaccess or php.ini that would
    affect this? The dev env is running php 5.2.6. Appreciate your help.

    - Raheem
  • Jerry Stuckle

    #2
    Re: include file path problem

    Raheem wrote:
    Hello,
    >
    I built a development version of a live website on my hosted account.
    However the development version is having problems with finding
    include files. After troubleshooting I was able to resolve the issue
    by removing the ../ from the beginning of the include file path. But
    now I am looking at making this modification hundreds of times in all
    kinds of files. I'd like to keep the dev env similar to the live env
    so I can port changes easily. Below is an example of working and non-
    working include file definitions:
    >
    working - include_once("d blib/db_con.php");
    non-working - include_once(". ./dblib/db_con.php");
    >
    But I dont understand why this would work in one server and not the
    other. Is there some kind of setting in htaccess or php.ini that would
    affect this? The dev env is running php 5.2.6. Appreciate your help.
    >
    - Raheem
    >
    The first one looks in the current directory. The second one looks in
    one directory lower. It looks like your file setup is different between
    your test and production servers.

    BTW - I always use absolute paths instead of relative. That way if I
    move a file that includes something else, it still works, i.e.

    include ($_SERVER['DOCUMENT_ROOT'] . '/dblib/db_con.php');

    This looks for the file in the dblib of the web root directory.

    P.S. If you MUST post to multiple newsgroups, please crosspost. Don't
    multipost.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • sheldonlg

      #3
      Re: include file path problem

      Jerry Stuckle wrote:
      Raheem wrote:
      >Hello,
      >>
      >I built a development version of a live website on my hosted account.
      >However the development version is having problems with finding
      >include files. After troubleshooting I was able to resolve the issue
      >by removing the ../ from the beginning of the include file path. But
      >now I am looking at making this modification hundreds of times in all
      >kinds of files. I'd like to keep the dev env similar to the live env
      >so I can port changes easily. Below is an example of working and non-
      >working include file definitions:
      >>
      >working - include_once("d blib/db_con.php");
      >non-working - include_once(". ./dblib/db_con.php");
      >>
      >But I dont understand why this would work in one server and not the
      >other. Is there some kind of setting in htaccess or php.ini that would
      >affect this? The dev env is running php 5.2.6. Appreciate your help.
      >>
      >- Raheem
      >>
      >
      The first one looks in the current directory. The second one looks in
      one directory lower. It looks like your file setup is different between
      your test and production servers.
      >
      BTW - I always use absolute paths instead of relative. That way if I
      move a file that includes something else, it still works, i.e.
      >
      include ($_SERVER['DOCUMENT_ROOT'] . '/dblib/db_con.php');
      >
      This looks for the file in the dblib of the web root directory.
      >
      P.S. If you MUST post to multiple newsgroups, please crosspost. Don't
      multipost.
      >

      Huh?

      The first one looks for the dblib directory in the current directory and
      then looks for dbcon.php. It is equivalent to ./dblib/db_con.php.

      The second one looks for a directory, dblib, which is on the same level
      as the current directory. IOW, it goes up one level and then tries to
      find the directory dblib and in that directory looks for db_con.php.

      Apparently, since the first one worked and the second didn't, the dblib
      directory must be in the current directory.

      Comment

      • Raheem

        #4
        Re: include file path problem

        Thanks for your help guys! I have a better understanding now. The
        solution was to use symlinks. Full solution listed in

        Comment

        • Raheem

          #5
          Re: include file path problem

          True, if the live site needs to be moved, its going to be a major
          problem. But due to contractual limitations, my work cannot change the
          client's site structure etc. That is why I need the dev env to be
          exact as the live env - so that I can port changes.

          Comment

          • Jerry Stuckle

            #6
            Re: include file path problem

            sheldonlg wrote:
            Jerry Stuckle wrote:
            >Raheem wrote:
            >>Hello,
            >>>
            >>I built a development version of a live website on my hosted account.
            >>However the development version is having problems with finding
            >>include files. After troubleshooting I was able to resolve the issue
            >>by removing the ../ from the beginning of the include file path. But
            >>now I am looking at making this modification hundreds of times in all
            >>kinds of files. I'd like to keep the dev env similar to the live env
            >>so I can port changes easily. Below is an example of working and non-
            >>working include file definitions:
            >>>
            >>working - include_once("d blib/db_con.php");
            >>non-working - include_once(". ./dblib/db_con.php");
            >>>
            >>But I dont understand why this would work in one server and not the
            >>other. Is there some kind of setting in htaccess or php.ini that would
            >>affect this? The dev env is running php 5.2.6. Appreciate your help.
            >>>
            >>- Raheem
            >>>
            >>
            >The first one looks in the current directory. The second one looks in
            >one directory lower. It looks like your file setup is different
            >between your test and production servers.
            >>
            >BTW - I always use absolute paths instead of relative. That way if I
            >move a file that includes something else, it still works, i.e.
            >>
            >include ($_SERVER['DOCUMENT_ROOT'] . '/dblib/db_con.php');
            >>
            >This looks for the file in the dblib of the web root directory.
            >>
            >P.S. If you MUST post to multiple newsgroups, please crosspost. Don't
            >multipost.
            >>
            >
            >
            Huh?
            >
            The first one looks for the dblib directory in the current directory and
            then looks for dbcon.php. It is equivalent to ./dblib/db_con.php.
            >
            The second one looks for a directory, dblib, which is on the same level
            as the current directory. IOW, it goes up one level and then tries to
            find the directory dblib and in that directory looks for db_con.php.
            >
            Apparently, since the first one worked and the second didn't, the dblib
            directory must be in the current directory.
            >
            Which is basically what I said.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Motosauro

              #7
              Re: include file path problem

              Raheem ha scritto:
              Hello,
              >
              I built a development version of a live website on my hosted account.
              However the development version is having problems with finding
              include files. After troubleshooting I was able to resolve the issue
              by removing the ../ from the beginning of the include file path. But
              now I am looking at making this modification hundreds of times in all
              kinds of files. I'd like to keep the dev env similar to the live env
              so I can port changes easily. Below is an example of working and non-
              working include file definitions:
              >
              working - include_once("d blib/db_con.php");
              non-working - include_once(". ./dblib/db_con.php");
              >
              But I dont understand why this would work in one server and not the
              other. Is there some kind of setting in htaccess or php.ini that would
              affect this? The dev env is running php 5.2.6. Appreciate your help.
              >
              - Raheem

              A nice solution I use for keeping includes out of the way is to set two
              directives (they can be set in both php.ini and vhost file)
              Say your site has its root in /var/www/sitename/htdocs
              You create a dir which is: /var/www/sitename/includes
              then you set
              open_basedir('/var/www/sitename')
              And
              include_path='/var/www/sitename/includes';

              So your includes cannot by any means be served on their own, since they
              are out of the directory tree served by your webserver
              Just a little bit safer
              :)

              Comment

              • Jerry Stuckle

                #8
                Re: include file path problem

                Motosauro wrote:
                Raheem ha scritto:
                >Hello,
                >>
                >I built a development version of a live website on my hosted account.
                >However the development version is having problems with finding
                >include files. After troubleshooting I was able to resolve the issue
                >by removing the ../ from the beginning of the include file path. But
                >now I am looking at making this modification hundreds of times in all
                >kinds of files. I'd like to keep the dev env similar to the live env
                >so I can port changes easily. Below is an example of working and non-
                >working include file definitions:
                >>
                >working - include_once("d blib/db_con.php");
                >non-working - include_once(". ./dblib/db_con.php");
                >>
                >But I dont understand why this would work in one server and not the
                >other. Is there some kind of setting in htaccess or php.ini that would
                >affect this? The dev env is running php 5.2.6. Appreciate your help.
                >>
                >- Raheem
                >
                >
                A nice solution I use for keeping includes out of the way is to set two
                directives (they can be set in both php.ini and vhost file)
                Say your site has its root in /var/www/sitename/htdocs
                You create a dir which is: /var/www/sitename/includes
                then you set
                open_basedir('/var/www/sitename')
                And
                include_path='/var/www/sitename/includes';
                >
                So your includes cannot by any means be served on their own, since they
                are out of the directory tree served by your webserver
                Just a little bit safer
                :)
                >
                You don't even need access to the php.ini file (not available at most
                shared hosts). PHP can access anything on the file system your host
                allows you to - and the better ones will allow you to access one level
                below the web root. So you can use something like:

                include ($_SERVER['DOCUMENT_ROOT'] . '/../include/myinclude.php') ;

                Assuming your document root points to /var/www/example/html, this gets
                the file from /var/www/example/include.

                And if your hosting company doesn't give you access, you're probably
                better off getting another hosting company, anyway.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Motosauro

                  #9
                  Re: include file path problem

                  Jerry Stuckle ha scritto:
                  Motosauro wrote:
                  >Raheem ha scritto:
                  >>Hello,
                  >>>
                  >>I built a development version of a live website on my hosted account.
                  >>However the development version is having problems with finding
                  >>include files. After troubleshooting I was able to resolve the issue
                  >>by removing the ../ from the beginning of the include file path. But
                  >>now I am looking at making this modification hundreds of times in all
                  >>kinds of files. I'd like to keep the dev env similar to the live env
                  >>so I can port changes easily. Below is an example of working and non-
                  >>working include file definitions:
                  >>>
                  >>working - include_once("d blib/db_con.php");
                  >>non-working - include_once(". ./dblib/db_con.php");
                  >>>
                  >>But I dont understand why this would work in one server and not the
                  >>other. Is there some kind of setting in htaccess or php.ini that would
                  >>affect this? The dev env is running php 5.2.6. Appreciate your help.
                  >>>
                  >>- Raheem
                  >>
                  >>
                  >A nice solution I use for keeping includes out of the way is to set
                  >two directives (they can be set in both php.ini and vhost file)
                  >Say your site has its root in /var/www/sitename/htdocs
                  >You create a dir which is: /var/www/sitename/includes
                  >then you set
                  >open_basedir ('/var/www/sitename')
                  >And
                  >include_path ='/var/www/sitename/includes';
                  >>
                  >So your includes cannot by any means be served on their own, since
                  >they are out of the directory tree served by your webserver
                  >Just a little bit safer
                  >:)
                  >>
                  >
                  You don't even need access to the php.ini file (not available at most
                  shared hosts). PHP can access anything on the file system your host
                  allows you to - and the better ones will allow you to access one level
                  below the web root. So you can use something like:
                  >
                  include ($_SERVER['DOCUMENT_ROOT'] . '/../include/myinclude.php') ;
                  >
                  Assuming your document root points to /var/www/example/html, this gets
                  the file from /var/www/example/include.
                  >
                  And if your hosting company doesn't give you access, you're probably
                  better off getting another hosting company, anyway.
                  >
                  Right:
                  One need to remember to set (or check) the open_basedir directive
                  I'd rather point to *include('inclu de/myinclude.php') * though

                  Comment

                  • Raheem

                    #10
                    Re: include file path problem

                    Everyone, thanks for the comments. Jensen the live env uses
                    include_once(". ./dblib/db_con.php"). But that path does not work on
                    the DEV env unless changed to include_once("d blib/db_con.php"). Using
                    symlinks, I am able to get the DEV site working without modifying
                    hundreds of references to the include files and also keep the dev and
                    live files the same. Your fullpath suggestion makes sense but in this
                    instance (adding functionality to a site built by someone else);
                    changing to a fullpath syntax would require lots of code changes,
                    which I would not be paid for, and could potentially break the site. I
                    am leery about changing someone else's code (esp undocumented code)
                    unless I absolutely have to.

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: include file path problem

                      Raheem wrote:
                      Everyone, thanks for the comments. Jensen the live env uses
                      include_once(". ./dblib/db_con.php"). But that path does not work on
                      the DEV env unless changed to include_once("d blib/db_con.php"). Using
                      symlinks, I am able to get the DEV site working without modifying
                      hundreds of references to the include files and also keep the dev and
                      live files the same. Your fullpath suggestion makes sense but in this
                      instance (adding functionality to a site built by someone else);
                      changing to a fullpath syntax would require lots of code changes,
                      which I would not be paid for, and could potentially break the site. I
                      am leery about changing someone else's code (esp undocumented code)
                      unless I absolutely have to.
                      >
                      Then change your development environment to match that of the production
                      system (that's how you should have it set up, anyway). You don't need
                      symlinks if the two are set up the same way.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      Working...