View Full Version : PHP Include - absolute versus relative path
04-30-2009, 12:03 AM
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.
Can anyone help me with this.
04-30-2009, 12:19 AM
<?php include("/navmenu/menu.php"); ?>
<?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:
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
04-30-2009, 08:40 AM
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.
04-30-2009, 08:59 AM
If I sound desperate it is because I am.
Enable error reporting and display errors (if you haven't dome this yet), by adding
at the top of your page, which will help you to debug the issues.
04-30-2009, 09:18 AM
in your code put:
That will display the set document for you. Tell me what that says but also put abduraooft code at the top of your page
04-30-2009, 09:57 AM
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.
04-30-2009, 09:59 AM
Your PHP code is not getting parsed, look at the browser's view source option,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<link rel="stylesheet" href="includes/cshop.css" type="text/css" media="screen" />
<link rel="stylesheet" href="includes/test.css" type="text/css" media="screen" />
<table width="140" border="0" align="center" cellpadding="0" cellspacing="0">
<td align="left" valign="middle"><?php include("navmenu/menu.php"); ?> </td>
<p><?php echo $_SERVER["DOCUMENT_ROOT"]; ?> </p>
There is something really wrong with your host!
04-30-2009, 10:12 AM
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.
04-30-2009, 11:48 AM
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.
04-30-2009, 11:54 AM
That link seems to be working now. I can see a nav menu and the View Source displays the parsed php.
04-30-2009, 12:08 PM
yeah me too. cool :D Bet your happy now Anita?
04-30-2009, 12:37 PM
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.
04-30-2009, 03:15 PM
You have to admit it looks quite cool doesn't it?
Yes I liked it :D
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.
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.