SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: include?

  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    include?

    I am including this php file,
    PHP Code:
    <?php include '../db/conn.php'?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="/masterasp/css/style.css">
    which works here,
    http://fixmysite.us/masterasp/providers/
    But doesn't here,
    http://fixmysite.us/masterasp/register.php
    I guess its because of this
    PHP Code:

    <?php include '../db/conn.php'?>
    How do I change the path so its path would vary depending on what directory im in on my server?

    Thanks
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    78
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It looks like you have gone one too many directories up. I presume the "db" folder is inside of the "masterasp" folder? If so, then try the following:
    PHP Code:
    <?php
    include './db/conn.php';
    include 
    '/db/conn.php'#should also work
    include 'db/conn.php'#should again work
    ?>
    By deleting one of the front periods, we are now searching for the "db" folder inside of the current directory, rather than heading one directory up into the main domain folder when searching for you "db" folder.

    You could also use an absolute path, instead of calculating the whereabouts of the connection file relative to the file system you are working in.

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    that worked, thanks.

    If the . thing looks in the current folder, why does it work when im in another folder?
    http://fixmysite.us/masterasp/providers/
    (the include is in the /masterasp/inc folder)
    (So inside http://fixmysite.us/masterasp/providers/
    I have
    PHP Code:
    <?php include '../inc/head.php'?>
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    78
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lukeurtnowski View Post
    that worked, thanks.

    If the . thing looks in the current folder, why does it work when im in another folder?
    http://fixmysite.us/masterasp/providers/
    (the include is in the /masterasp/inc folder)
    (So inside http://fixmysite.us/masterasp/providers/

    PHP Code:
    <?php include '../inc/head.php'?>
    The code you have given shows that you are looking at the next directory up from the "providers" folder, into "masterasp" (where the "inc" folder exists). Am I missing something?

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Try this:

    PHP Code:
    <?php include $_SERVER['DOCUMENT_ROOT'].'/masterasp/db/conn.php'?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="/masterasp/css/style.css">
    Also, please note that it's not the best idea in the world to make files with db credentials etc world viewable; better to put them somewhere above the document root.
    If you *have* to put them there, make sure to add a .htaccess file in the directory that denies direct access via web (php will still be able to read files in that directory no problem)

    .htaccess:
    Code:
    deny from all
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

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