Php configuration - include path problem

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

    Php configuration - include path problem

    Hi,

    I've got a php script located at : http://localhost/browse/script.php
    This script is "URL-rewrited" as http://localhost/welcome.htm

    This script includes other scripts with the following code :

    <?php
    include("../inc/connect.php") ;
    ....
    ?>

    When I directly type : http://localhost/browse/script.php => it works
    As when I go to : http://localhost/welcome.htm => Error could not find
    "../inc/connect.php" !!

    I've just changed my apache/php/mysql conf (and unfortunately lost the one I
    had before) : I switched to xampp.
    This script used to work perfectly before :-( !!!
    I do understand that paths are different for the client code but I don't
    understand why it could be the same with server code !
    I suspect Apache / Php conf to be the cause of my problem... but I can't
    find out !
    Can you help me, it's quite importante.

    Thanks in advance,

    --
    alex


  • Justin Koivisto

    #2
    Re: Php configuration - include path problem

    alex wrote:[color=blue]
    > Hi,
    >
    > I've got a php script located at : http://localhost/browse/script.php
    > This script is "URL-rewrited" as http://localhost/welcome.htm
    >
    > This script includes other scripts with the following code :
    >
    > <?php
    > include("../inc/connect.php") ;
    > ...
    > ?>
    >
    > When I directly type : http://localhost/browse/script.php => it works[/color]

    path is like:
    /home/user/www/inc/connect.php
    [color=blue]
    > As when I go to : http://localhost/welcome.htm => Error could not find
    > "../inc/connect.php" !![/color]

    path is like:
    /home/user/inc/connect.php
    [color=blue]
    > I do understand that paths are different for the client code but I don't
    > understand why it could be the same with server code ![/color]

    You may have had the include path set with the "inc" directory included.

    include_path = ".:./inc"
    [color=blue]
    > I suspect Apache / Php conf to be the cause of my problem... but I can't
    > find out !
    > Can you help me, it's quite importante.
    >
    > Thanks in advance,
    >[/color]

    Comment

    • alex

      #3
      Re: Php configuration - include path problem

      > You may have had the include path set with the "inc" directory included.[color=blue]
      >
      > include_path = ".:./inc"
      >[/color]

      thanks, but this would only work for this particular file.
      In fact, I have many scripts in many different directories (several projects
      on the same machine : localhost/project_A, localhost/project_B, ...).
      I would be impossible to maintain if I had to update the "include_pa th" var
      every time I get a new project.
      The trouble is I never changed this option before and it used to work. I
      can't understand why.

      FYI : I run under windows and my current "include_pa th" is :
      include_path = ".;C:\Progr am Files\xampp\php \pear\"

      it's the default value in xampp.


      Comment

      • alex

        #4
        Re: Php configuration - include path problem

        > I would be impossible to maintain if I had to update the "include_pa th"[color=blue]
        > var every time I get a new project.[/color]

        Sorry, this is a mistake... the '.' directory in the include_path would
        solve my pb... but it doesn't :'-(


        Comment

        • Justin Koivisto

          #5
          Re: Php configuration - include path problem

          alex wrote:[color=blue][color=green]
          >> I would be impossible to maintain if I had to update the "include_pa th"
          >> var every time I get a new project.[/color]
          >
          > Sorry, this is a mistake... the '.' directory in the include_path would
          > solve my pb... but it doesn't :'-(
          >
          >[/color]

          try adding it like:

          include_path = ".:/path/to/inc"

          Comment

          • alex

            #6
            Re: Php configuration - include path problem

            > try adding it like:[color=blue]
            >
            > include_path = ".:/path/to/inc"[/color]

            it doesn't work :-(


            Comment

            • David Haynes

              #7
              Re: Php configuration - include path problem

              alex wrote:[color=blue][color=green]
              >> try adding it like:
              >>
              >> include_path = ".:/path/to/inc"[/color]
              >
              > it doesn't work :-(
              >
              >[/color]
              Just to be clear.
              "/path/to/inc" in your case is an absolute path not a relative one - right?

              For example:
              if your web site is hosted in /opt/web/my_site
              and your include files are in /opt/web/my_site/includes

              then your include_path would be ".:/opt/web/my_site/includes"

              -david-

              Comment

              • Jerry Stuckle

                #8
                Re: Php configuration - include path problem

                alex wrote:[color=blue]
                > Hi,
                >
                > I've got a php script located at : http://localhost/browse/script.php
                > This script is "URL-rewrited" as http://localhost/welcome.htm
                >
                > This script includes other scripts with the following code :
                >
                > <?php
                > include("../inc/connect.php") ;
                > ...
                > ?>
                >
                > When I directly type : http://localhost/browse/script.php => it works
                > As when I go to : http://localhost/welcome.htm => Error could not find
                > "../inc/connect.php" !!
                >
                > I've just changed my apache/php/mysql conf (and unfortunately lost the one I
                > had before) : I switched to xampp.
                > This script used to work perfectly before :-( !!!
                > I do understand that paths are different for the client code but I don't
                > understand why it could be the same with server code !
                > I suspect Apache / Php conf to be the cause of my problem... but I can't
                > find out !
                > Can you help me, it's quite importante.
                >
                > Thanks in advance,
                >[/color]

                For stuff based off your website's root directory, don't even use the
                include path. Just use absolute paths based on the document root, i.e.

                $_SERVER['DOCUMENT_ROOT']] . '/inc/connect.php'

                Works in every setup of Apache, and is transportable. No .ini file
                changes required.


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

                Comment

                • alex

                  #9
                  Re: Php configuration - include path problem

                  > Just to be clear.[color=blue]
                  > "/path/to/inc" in your case is an absolute path not a relative one -
                  > right?
                  > For example:
                  > if your web site is hosted in /opt/web/my_site
                  > and your include files are in /opt/web/my_site/includes
                  >
                  > then your include_path would be ".:/opt/web/my_site/includes"
                  >
                  > -david-
                  >[/color]

                  Ok, it's clear.
                  Still, it doesn't work :-(
                  I think it comes from the URL rewriting as the "not URL-rewrited" file works
                  but not the "URL rewrited" one.
                  What do you think ?


                  Comment

                  • David Haynes

                    #10
                    Re: Php configuration - include path problem

                    alex wrote:[color=blue][color=green]
                    >> Just to be clear.
                    >> "/path/to/inc" in your case is an absolute path not a relative one -
                    >> right?
                    >> For example:
                    >> if your web site is hosted in /opt/web/my_site
                    >> and your include files are in /opt/web/my_site/includes
                    >>
                    >> then your include_path would be ".:/opt/web/my_site/includes"
                    >>
                    >> -david-
                    >>[/color]
                    >
                    > Ok, it's clear.
                    > Still, it doesn't work :-(
                    > I think it comes from the URL rewriting as the "not URL-rewrited" file works
                    > but not the "URL rewrited" one.
                    > What do you think ?
                    >
                    >[/color]
                    Follow Jerry Stuckle's advise and make the include relative to
                    $_SERVER['DOCUMENT_ROOT'].

                    In my case, my includes are not in the web tree, so setting the path is
                    appropriate.

                    BTW: I don't think URL rewriting has any affect on the include_path
                    since a) the path is absolute and b) PHP does care about URLs.

                    -david-

                    Comment

                    • d

                      #11
                      Re: Php configuration - include path problem

                      "alex" <alex@nospam.or g> wrote in message
                      news:440f1491$0 $24200$636a55ce @news.free.fr.. .[color=blue][color=green]
                      >> You may have had the include path set with the "inc" directory included.
                      >>
                      >> include_path = ".:./inc"
                      >>[/color]
                      >
                      > thanks, but this would only work for this particular file.
                      > In fact, I have many scripts in many different directories (several
                      > projects on the same machine : localhost/project_A, localhost/project_B,
                      > ...).
                      > I would be impossible to maintain if I had to update the "include_pa th"
                      > var every time I get a new project.
                      > The trouble is I never changed this option before and it used to work. I
                      > can't understand why.[/color]

                      You should use subhosts to keep your sites sane on your machine. Keeping
                      seperate sites on one domain is asking for trouble :)
                      [color=blue]
                      > FYI : I run under windows and my current "include_pa th" is :
                      > include_path = ".;C:\Progr am Files\xampp\php \pear\"
                      >
                      > it's the default value in xampp.
                      >[/color]


                      Comment

                      • alex

                        #12
                        Re: Php configuration - include path problem

                        Sorry, I was away for a while.
                        [color=blue]
                        > Follow Jerry Stuckle's advise and make the include relative to
                        > $_SERVER['DOCUMENT_ROOT'].[/color]

                        Ok, my problem is that I have many included scripts to change :-(
                        [color=blue]
                        > In my case, my includes are not in the web tree, so setting the path is
                        > appropriate.
                        >
                        > BTW: I don't think URL rewriting has any affect on the include_path since
                        > a) the path is absolute and b) PHP does care about URLs.[/color]

                        That's exaclty what I think... and it's the case on my production server
                        (and it was on my local machine few days ago).
                        Still, with my brand new xampp set up on my local dev machine, I now have
                        this problem (I didn't encounter it before with apache/php/mysql and zend
                        server).

                        I found a "solution" => adding http redirection in all my rewrite
                        conditions, i.e :
                        before : RewriteCond ^test$ /test.htm
                        after : RewriteCond ^test$ /test.htm [R=304]

                        It works but doesn't really satisfy me.

                        --
                        alex


                        Comment

                        • alex

                          #13
                          Re: Php configuration - include path problem

                          > You should use subhosts to keep your sites sane on your machine. Keeping[color=blue]
                          > seperate sites on one domain is asking for trouble :)
                          >[/color]

                          Thanks, I didn't know this.


                          --
                          alex


                          Comment

                          • Jerry Stuckle

                            #14
                            Re: Php configuration - include path problem

                            alex wrote:[color=blue]
                            > Sorry, I was away for a while.
                            >
                            >[color=green]
                            >>Follow Jerry Stuckle's advise and make the include relative to
                            >>$_SERVER['DOCUMENT_ROOT'].[/color]
                            >
                            >
                            > Ok, my problem is that I have many included scripts to change :-(
                            >
                            >[/color]

                            And the longer you wait, the more work it will be.


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

                            Comment

                            Working...