lovelys Posted May 11, 2007 Share Posted May 11, 2007 Guys im getting prob for including the file. I have a menu.php file in my site and I want to include that in many pages. please help me Quote Link to comment https://forums.phpfreaks.com/topic/50905-help-with-include-function/ Share on other sites More sharing options...
bhavin_85 Posted May 11, 2007 Share Posted May 11, 2007 use include("menu.php") Quote Link to comment https://forums.phpfreaks.com/topic/50905-help-with-include-function/#findComment-250375 Share on other sites More sharing options...
chronister Posted May 11, 2007 Share Posted May 11, 2007 I had a similar problem the other day. PHP does not have a "start at the root of the site" directive like HTML does. Basically what you are going to have to do is use something like this on each page, changing each one to fit where the include file is in relation to the file your including into include('menu.php'); include('../menu.php'); include('folder1/menu.php'); ../ takes you back 1 folder level Hope this helps, if not, then post back with your directory structure and I can help more there Nate Quote Link to comment https://forums.phpfreaks.com/topic/50905-help-with-include-function/#findComment-250376 Share on other sites More sharing options...
lovelys Posted May 11, 2007 Author Share Posted May 11, 2007 include('../menu.php'); can i do this if my menu.php is in root folder and i want to use it in folder1 directory? httpdocs:/includes/menu.php here i have th file httpdocs:/coverstory/index.php in this index.php im including menu.php. Currently I have menu.php also in coverstory folder so its working. Quote Link to comment https://forums.phpfreaks.com/topic/50905-help-with-include-function/#findComment-250386 Share on other sites More sharing options...
chronister Posted May 11, 2007 Share Posted May 11, 2007 If your wanting to simply get your menu on all pages so you don't have to edit it all the time try something like this. Use a standard header / footer template. I am using a table based layout in this example main.php <html> <head> <title></title> </head> <body> <table width="75%" height="500" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="75" colspan="2" align="center">Banner Goes Here </td> </tr> <tr> <td width="200" align="center">Menu Goes Here </td> <td> All content loads here <?php function footer(){ ?> </td> </tr> <tr> <td height="15" colspan="2" align="center">Footer Goes Here </td> </tr> </table> </body> <? } ?> The rest of your pages only need to look like this <?php include('main.php') ?> This content here will always load in the cell marked content <?php footer(); ?> I find this method much easier to work with. But onto your question. yes, if your directory structure is something like this /root | folder1 |--index.php |folder2 |-- index.php index.php menu.php Then to include the menu inside folder 1 or 2, you use include('../menu.php'); at the root index.php you use include('menu.php'); Quote Link to comment https://forums.phpfreaks.com/topic/50905-help-with-include-function/#findComment-250390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.