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 13 of 13
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    Cape Town
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts

    PHP Include - absolute versus relative path

    Hi all,

    For some reason that I don't understand my web server refuses to include my php include menu page. I have tried every trick that I have learned, used the htaccess method, renamed directories and files but under no circumstance does my include want to work on the web server. It works absolutely perfect on my local Apache testing server though.

    I am trying to include 'menu.php' into 'home.php' (menu.php resides in a root folder called 'navmenu')
    This is the code I insert into a table into the home.php page: <?php include("navmenu/menu.php"); ?>

    I read in the archives here that there is an absolute path and a relative path method that can be used to direct to the called file. Can this be the reason why it is not working? Am I on the wrong track once again?

    If I sound desperate it is because I am.

    Anita.

    Can anyone help me with this.

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Try these
    PHP Code:
    <?php include("/navmenu/menu.php"); ?>
    or

    PHP Code:
    <?php include($_SERVER["DOCUMENT_ROOT"]."/navmenu/menu.php"); ?>
    As long as navmenu sits inside your document root the above method should work. I mean if you were to list your document root would it look like this:

    /home.php
    /mavmenu/

    In otherwords are the home.php file and the navmenu folder inside the same folder?

    Heres are some rules

    Put a / infront to start from the document root of that host.
    Put nothing infront to start in the current directory which is the same as ./ infront
    Put ../ to go up a level
    Put ../../ to go up two level
    etc
    Last edited by timgolding; 04-30-2009 at 01:23 AM.
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New Coder
    Join Date
    Apr 2009
    Location
    Cape Town
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Good morning timgolding,

    Thank you once again for the great help but unfortunately none of your suggestions work.

    I am going to phone my hosting company quickly.

    Anita.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    If I sound desperate it is because I am.
    Enable error reporting and display errors (if you haven't dome this yet), by adding
    PHP Code:
    <?php
    ini_set
    ('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting (E_ALL);
    ?>
    at the top of your page, which will help you to debug the issues.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    in your code put:

    PHP Code:
    <?php
    echo $_SERVER["DOCUMENT_ROOT"];
    ?>
    That will display the set document for you. Tell me what that says but also put abduraooft code at the top of your page
    You can not say you know how to do something, until you can teach it to someone else.

  • #6
    New Coder
    Join Date
    Apr 2009
    Location
    Cape Town
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi all,
    I have done as you instructed and inserted the code into 'test8.php'.

    This is the site link http://www.customshop.co.za/test8.php

    Nothing but the page is displayed.

    Anita.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Your PHP code is not getting parsed, look at the browser's view source option,
    PHP Code:
    <?php
    ini_set
    ('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting (E_ALL);
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Nav Test</title>
    <link rel="stylesheet" href="includes/cshop.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="includes/test.css" type="text/css" media="screen" />
    </head>
    <body id="test8">
    <table width="140" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="left" valign="middle"><?php include("navmenu/menu.php"); ?>&nbsp;</td>
      </tr>

    </table>
    <p><?php echo $_SERVER["DOCUMENT_ROOT"]; ?>&nbsp;</p>
    </body>
    </html>
    There is something really wrong with your host!
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    New Coder
    Join Date
    Apr 2009
    Location
    Cape Town
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks you all so far,

    This is driving me nuts! I have just sent another urgent email to my hosting company for clarification. I will keep you informed.

    If you have any other suggestions please let me know.

    xxxx
    Anita.

  • #9
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Ha your sure the file ends with .php extension if so contact your host and tell them that php is not getting passed. Say you called the file .php but when you put codes inside <?php ?> tags the codes come through to my browser.
    You can not say you know how to do something, until you can teach it to someone else.

  • #10
    New Coder
    Join Date
    Jan 2009
    Posts
    91
    Thanks
    17
    Thanked 1 Time in 1 Post
    That link seems to be working now. I can see a nav menu and the View Source displays the parsed php.

  • #11
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    yeah me too. cool Bet your happy now Anita?
    You can not say you know how to do something, until you can teach it to someone else.

  • #12
    New Coder
    Join Date
    Apr 2009
    Location
    Cape Town
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi everyone,

    I guess you can see that it's starting to work. The fault was on the hosting company's side. Apparently some "setting that was incorrect" was changed and they will also "restructure the account to a FastCGI server" is what I have been told.

    Let's hold thumbs! I really want to move on from this menu now. You have to admit it looks quite cool doesn't it?

    Thanks once again for the incredible help. Timgolding and Abduraooft - you're stars in this coding world that I have now stuck my foot into. I am tempted to give you more thanks but maybe that won't be etiquette.

    I will let you know if it continues to work. What really ****** me off is that I had it right in the beginning - a week ago, thanks largely to abduraooft's expertise.

    My next questions will probably relate to password protection for all the pages after index.html to prevent people from vieving it whilst under development. And does anyone know of an easy way to add a blog "thing" to a website? Maybe this isn't the right place, but anyway!

    I feel quilty already.

    Anita

  • #13
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by Anita2105 View Post
    You have to admit it looks quite cool doesn't it?
    Yes I liked it

    Quote Originally Posted by Anita2105 View Post
    My next questions will probably relate to password protection for all the pages after index.html to prevent people from viewing it whilst under development. And does anyone know of an easy way to add a blog "thing" to a website? Maybe this isn't the right place, but anyway!

    I feel guilty already.

    Anita
    Don't feel guilty though I only help people here because i like helping people here. If you just want to block other people from viewing that you can do that lots of different ways. First question is did they get htaccess working? Are you on a static or dynamic IP. In otherwords the computer you are working on it from does its IP address change. You can use http://www.whatismyip.com/ to check on two different days to see if the IP changes. If it doesn't change then it will be easy with some simple php or htaccess authentication. If not then you will have to password protect or something. If it was me though I would just develop everything on my computer first then when the whole sites done upload it to live. But i guess after the troubles you have had with your live server you might not be willing to take this approach?

    With regards to the blog you possibly need a log in system. Even if not you will need to create an SQL database and learn how to query that databse with php. Your blog would need flood protection probably. And there would be all sorts of security issues you would have to tackle. There might be some ready made ones you can use however.
    Last edited by timgolding; 04-30-2009 at 04:20 PM.
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

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