include() and absolute path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rajuvk@satyam.net.in

    #1

    include() and absolute path

    I am setting up a website with a number of folders like:
    / (the document root)
    /user
    /admin/
    /content
    in the /user folder there is a flie "userlogged.php ", which I want to
    include in every file. If in the file "/content/index.php", if I use
    the relative path and place the include like this
    "../user/userlogged.php" , it will work fine. But when I use the
    absolute path like "/user/userlogged.php" , it is not working ?. I have
    read in several posts that the absolute path will work with include().
    ( Or am I wrong ?)
    can any body tell me how to enable the absolute path method ?. The
    relative path method is fine but when going deep with many subfolders,
    the path will be come lengthy with "../../" and is difficult to
    maintain and is a problem when moving the pages around. using absolute
    path is a remedy to this.

    is there any other method/ function similar to include(), to place
    content of a file in another file ?

    thanks ina dvance.

    Raju V.K.

  • Taare

    #2
    Re: include() and absolute path

    When you use include("/mypath/myfile.php") it doesnt look in the path
    relative to http://mysite.com/ but rather relative to your system root.
    You can make a .htaccess file that looks like this:
    php_flag include_path "/home/me/myphpfiles/:."

    And do include("user/userlogged.php" ) and will then first look for
    /home/me/myphpfiles/user/userlogged.php, if it's not found, it will be
    looked for relative to the current path.

    Comment

    • rajuvk@satyam.net.in

      #3
      Re: include() and absolute path

      Does the PHP and HTML behave differently when it comes to paths ?. If
      I give /user/userlogged.php as the address of a page in the <a></a>
      tag, it will always loads the userlogged.php page from the /user
      folder, from the document root of the web-site. (That is
      http://mysite.com/user/userlogged.php). I wish to repeat this behaviour
      in PHP include(). Irrespectice of the location of the file calling the
      include function, the page userlogged.php shall be included. What is
      the best way to achieve this ?

      Regards,
      Raju

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: include() and absolute path

        rajuvk@satyam.n et.in wrote:[color=blue]
        > Does the PHP and HTML behave differently when it comes to paths ?.[/color]
        If[color=blue]
        > I give /user/userlogged.php as the address of a page in the <a></a>
        > tag, it will always loads the userlogged.php page from the /user
        > folder, from the document root of the web-site. (That is
        > http://mysite.com/user/userlogged.php). I wish to repeat this[/color]
        behaviour[color=blue]
        > in PHP include(). Irrespectice of the location of the file calling[/color]
        the[color=blue]
        > include function, the page userlogged.php shall be included. What is
        > the best way to achieve this ?[/color]

        I'm afraid, it is very hard to help you here--you seem to lack the
        basic idea of filesystems. You definitely have to look at file system
        basics and HTTP basics.

        --
        <?php echo 'Just another PHP saint'; ?>
        Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

        Comment

        Working...