PHP - Include() Inside Another Include()
Hi Guys.. Merry Christmas
Im kinda new to this fantastic world of PHP and i have a little problem i hope you can help me with. Im trying to build a website where I use include() to genereate my content. On my index.php i have a menu which includes content in a content div from external .php pages, my structure kinda goes like this.. (simplified) site/ index.php content/ fronpage.php products.php contact.php The HTML looks like this. <div id="menu"> <ul> <li><a href="index.php?page=frontpage">frontpage</a></li> <li><a href="index.php?page=products">frontpage</a></li> <li><a href="index.php?page=contact">frontpage</a></li> </ul> </div <div id="main"> <?php include('/content/'.$_GET['page'].'.php'); ?> </div> This all works very fine, but my problem is, can I have a include inside an already included page? I would like to have a menu on my products.php site, but that page is already included from above, and i would like the menu on the products.php site to stay as the content from the nested include changes with input from the /products folder. my idea was something like this. site/ index.php content/ frontpage.php products.php contact.php products/ product1.php product2.php the HTML on the index.php is the same as above and then i would add the include() on the products.php page, so its kinda the same thing, but one inside the other. HTML inside the products.php folder <div id="sub_menu"> <ul> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> </ul> </div <div id="sub_main"> <?php include('/content/products'.$_GET['#'].'.php'); ?> </div> I dont know how to link to the new files so they will be included while the first include still stays on the page. Any of you know how and if this can be done? Or maybe at better way to do it? Hope this made sense, my first PHP question Thanks Similar TutorialsHi Still a new comer when it comes to PHP. I have a situation where I want to use an include within an include and I am having trouble with my file paths. My main header include, includes everything for each page of my site, beyond the opening of the body to incorporate my navigation etc conditionally loading in css, and loading in titles and meta data etc depending on the page in question. This header needs to reference another include called the-pod.php which is required for every page, the only trouble is I want to use / to reference the root of the server and this is breaking my code. I can't use ../../ etc as its a different path depending on where the master file is located. So my question is how do I get around this? Can the root of the server or path to the root be stored in a variable? and if so how would I write this. Any tips / advice will be greatly appreciated. CanI put one INCLUDE statement INSIDE of another INCLUDE statement? Is there any way to do this? My image is not appearing below. The text, "we are sorry..." is appearing... Code: [Select] if(!isset($_POST['comments'])) { died('<img src="images/head/head_error.gif"/><br>We are sorry, but there appears to be a problem with the form you submitted.'); } Ok I am not sure if this is possible but I hope someone out there can show me a way. I have a webpage with left content boxes that are looped in depending on the sql info. In one of the boxes the content of the box is going to be another page being pulled in. Now normally I would just put in the include ("page"); but its inside of an echo so you would end the echo do the include and then start the echo back up, however in this case its pulling in the coding from a variable so im a bit lost as to what to do now. The page would have something like... Code: [Select] echo ' '.html_entity_decode(stripslashes($info[content])).' '; and the info content part is Code: [Select] include("pages/paypalbox.php") I've tried making the variable Code: [Select] '; include("pages/paypalbox.php"); echo' Hoping that would fix it but I should of known better, the variable is being pulled in so its not processing it as part of the first step coding and it isn't going to do anything other then print it out like text. So is there a way to make this work? Thanks. I am trying to pass a variable from inside of a function in a file that is included eg include.php Code: [Select] <? function noms(){ $foobar = "apples"; } ?> main.php Code: [Select] <? include("include.php"); noms(); echo "these ". $foobar. " are most delicious... OM NOM NOM"; ?> I am essentially using a include file for a mysql connection and based on the connection outcome i am either setting a value to true or false. It prints "Connected succesfully" and what not just fine, but, after that it wont pass on the variables data. I know its the function because, it passes the data if i put the variable before the function... i just dont get it.. any help would be great. Thanks. Ansel I have a php file that generates a string that I need to use in a .js (javascript)file. Being that php developers sometimes using javascript with php, Im hoping someone can help me with this, cause i dont know any javascript. Code: [Select] //This is the varible inside the .js file var suggestionText = "I need to be able to include my string generated by the php file here..."; When I put this above all else in my document and test it offline, all I see is code in the browser. But when I test it on my web server, I can view the markup and whatnot. Does anyone know why this is? I have an include file and a php file in different directories and I can't figure out what I'm doing wrong trying to get them to relate to one another. webhost/website/includes/include.inc webhost/website/modules/module/page.php How do I get the page.php to use the include.inc file? I'd think it would be "../../include.inc", but that isn't working I am fairly new to PHP. I tried searching for answers on Google and in this forum, but I found no solutions. Problem I used PHP include as a way of navigating through my website. I did this so if I changed the design of the website, I don't have to edit each page. The function is similar to iframes. Yesterday I developed a tip calculator (calculates how much tip you need to give to the waiter or waitress based on your bill). However I've noticed after I press "submit", it sends the visitor to a page that shows only the results. I want to show the results within my website design. Screen shots: I input the data. Notice the gray background and the navigation bar. After I press "Submit Order", it shows the results but the results aren't within my website's design. (Notice the white background). Question: How can I incorporate the results from the tip calculator in my design after pressing the "Submit Order" button? Here is the code on the main page of my website (HTML/CSS with PHP) P.S For links in the navigation section, I used : ?id=name Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MV Book</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="wrapper2"> <div id="header"></div> <!-- End of Header --> <div id="navi"> <ul> <li><a href="/">Home</a></li> <li><a href="?id=tip">Tip calculator</a></li> <li><a href="?id=orderform">Tip calculator</a></li> </ul> </div> <!-- End of Navi --> <div id="content"> <?php $id = $_GET['id'] ; switch($id) { default: include('cutenews/show_news.php'); break; case "orderform": include('orderform.html'); break; case "tip": include('tip.php'); } ?> </div> <!-- End of Content --> </div> <!-- End of Wrapper 2 --> </div> <!-- End of Wrapper --> </body> </html> And this is the code that is on the page where I input the code: Code: [Select] <form action="processtip.php" method="POST"> <table border="0"> <tr> <td>Bill Amount</td> <td align="center"><input type="text" name="billamount" size="10" maxlength="10" id="billamount"></td> </tr> <td>Tip Percent (%)</td> <td align="center"><input type="text" name="tippercent" size="10" maxlength="10" id="tippercent"></td> </tr> <tr> <td>Number Of People (Split)</td> <td align="center"><input type="text" name="people" size="10" maxlength="10" id="people" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit Order"></td> </tr> </table> </form> This is the PHP Code that process the input data and displays the results (processtip.php) : Code: [Select] <?PHP $billamount = $_POST['billamount']; $tipnumber = $_POST['tipnumber']; $people = $_POST['people']; ?> <html> <head> <title>Emaj's Tip Calculator</title> </head> <body> <h1>Emaj's Tip Calculator</h1> <h2>Thanks for using my Online Tip Calculator</h2> <?php if ($billamount < 0) { echo "<p> You can't have a negative number. Does the restuarant owe you money?"; exit; } else { if ($billamount == 0) { echo "What's the point of using a tip calculator if you didn't order anything?<br />"; exit; } if ($billamount > 0) { echo "<p> Your bill is $".$billamount; } } $tippercent = 0; $tippercent = $tipnumber/100; $tipamount = 0; $tipamount = $billamount * $tippercent; echo "<p> Total tip is $".$tipamount; $totalamount = 0; $totalamount = $billamount + $tipamount; echo "<p>Total bill (Tip included) is $".$totalamount; echo "<p>You are splitting the Total Bill with ".$people." people."; $indperson = 0; $indperson = $totalamount/$people; echo "<p>Each individual person pays $".$indperson; ?> If there is a thread that has a similar problem with a solution, can you please post a link to it? Thank you and I apologize in advance if there's a duplicate thread. -Emaj Hi, I'm not really a php user however I'm having a dabble. I'm trying to display an include file such as <?php include("sponsor.php"); ?> However I'm trying to make it a bit more advanced by selecting the month so what I'm after doing is displaying <?php include("sponsor-october.php"); ?> The idea being that this updates by itself, I understand that <?php echo date("F"); ?> will display the month, it's just combining the two where I get lost, any help would be welcome ta. Hello, I created a script at my server, but would like to upload files to my other server. The website runs on server 1 and the upload form on server 2. I want to include the file of server 2 at the page at server 1; I've tried: include("http://ipaddress/upload.php"); Sadly, this doesn't work. I get the error: Quote URL file-access is disabled in the server configuration in Is there another way to do it? Or should I change the php.ini and allow this (why isn't it allowed by default? What are the risks?). iFrames aren't what I need here. Thanks, NLCJ I have a script that is going to be on several urls. There is a master site that will have certain information that will need to be present on all urls that host this script. I am planning on using RSS to do this. What is a good method to dynamically create the xml file for the master site so that the feed can be broadcast to the other urls? Thanks in advance for the input. Okay if I use an include to include a login script the login button doesn't work at all but it works on the page itself just not on the include http://store.crytell.com/ when I attempt to login nothing happens Im sure I have the script dir right Code: [Select] <body bgcolor="#100f14"> <? /** * Main.php * * This is an example of the main page of a website. Here * users will be able to login. However, like on most sites * the login form doesn't just have to be on the main page, * but re-appear on subsequent pages, depending on whether * the user has logged in or not. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 26, 2004 */ include("./storelogin/include/session.php"); ?> <html> <title>Jpmaster77's Login Script</title> <body> <table> <tr><td> <? /** * User has already logged in, so display relavent links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){ echo "<h1>Logged In</h1>"; echo "Welcome <b>$session->username</b>, you are logged in. <br><br>" ."[<a href=\"./storelogin/userinfo.php?user=$session->username\">My Account</a>] " ."[<a href=\"./storelogin/useredit.php\">Edit Account</a>] "; if($session->isAdmin()){ echo "[<a href=\"./storelogin/admin/admin.php\">Admin Center</a>] "; } echo "[<a href=\"./storelogin/process.php\">Logout</a>]"; } else{ ?> <h1>Login</h1> <? /** * User not logged in, display the login form. * If user has already tried to login, but errors were * found, display the total number of errors. * If errors occurred, they will be displayed. */ if($form->num_errors > 0){ echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>"; } ?> <form action="./storelogin/process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr> <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>> <font size="2">Remember me next time <input type="hidden" name="sublogin" value="1"> <input type="submit" value="Login"></td></tr> <tr><td colspan="2" align="left"><br><font size="2">[<a href="./storelogin/forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr> <tr><td colspan="2" align="left"><br>Not registered? <a href="./storelogin/register.php">Sign-Up!</a></td></tr> </table> </form> <? } /** * Just a little page footer, tells how many registered members * there are, how many users currently logged in and viewing site, * and how many guests viewing site. Active users are displayed, * with link to their user information. */ echo "</td></tr><tr><td align=\"center\"><br><br>"; echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>"; echo "There are $database->num_active_users registered members and "; echo "$database->num_active_guests guests viewing the site.<br><br>"; include("./storelogin/include/view_active.php"); ?> </td></tr> </table> </body> </html> Code: [Select] <?include_once "./storelogin/main.php"; // this will include a.php?> Hi, I'm so new to PHP. Kindly help me figure out on how to use include function.. situation is.. I am going to include a head.php file /includes/head.php this is the path where i want to include head.php /menu/menulist/list in "list" folder that is where I want to include head.php include works on folder "menulist" but not on 3rd folder "list" any advise on how tot solve this problem of mine? Thanks Hi, is there any way to clear the included file in php? for example, if i included a file like , include "file.php"; after using the functions in this file finally i want to exclude from the list. I have to store my Authorize.net Payment Gateway values somewhere safe. (i.e. Outside of the Web Root) I tried this code but my checkout page that formerly worked with local values in Test Mode is crashing. // Include Authorize.net Values. require_once('/var/www/vhosts/MyWebsite.com/private/auth_config.php'); I think the issue is that private maybe can't be read or included by other files? Would using another Linux directory solve my problem? Debbie Hi I have recently moved hosting providers; I have a php include on my website, which feeds latest posts from my forums to my homepage. The code I use is <?php include ('../mb/getposts/posts.php?id=80')?> Now, this code used to work on my old host, but no longer works on my new host, giving an error of Code: [Select] Warning: include(../mb/getposts/posts.php?id=80) [function.include]: failed to open stream: No such file or directory in /home/site/public_html/folder/page.php on line 41 Warning: include(../mb/getposts/posts.php?id=80) [function.include]: failed to open stream: No such file or directory in /home/site/public_html/folder/page.php on line 41 Warning: include() [function.include]: Failed opening '../mb/getposts/posts.php?id=80' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/site/public_html/folder/page.php on line 41 I can also include the script as <?php include ('../mb/getposts/posts.php')?> and when I do this the script works as it should do, but showing the default option. The ?id=xx bit allows me to choose what forum id I want the posts to be shown on my homepage as I have lots of individual homepages (long story) and to try and keep files small, I decided to wrap the latest posts php file into something where i could use one file for all the forums IDs that I need to show Does anyone know why this will not work? I am thinking it's a problem with the php config of my new server, and have asked my hosts, but they are telling me that this is out of their scope of support.. Any ideas would be appreciated Dear All, I have just signed up to the forums so hello. I'm a complete novice to PHP and have a question. I've written a site using PHP but am stuck, how I have written is that certain pages use INCLUDE files that pull out information from .TXT files. The question I have is, is it possible to contain another INCLUDE link within the .TXT file? i.e. index.php includes companyname.txt but companyname.txt only has this line of text in it: <?php include("../includes/moreinformation.txt"); ?> I know it is quite a weird question/request but is there a way of doing this? So basically have an include within an include although the file extensions are .TXT. Thanks and looking forward to any help from you Pros. Kindest regards, James. James. I am creating several files with the same connection information. I already REQUIRE_ONCE my connection data that has all the 'secret entry data', but am wondering, if this is my current code in the top of the files: $con = require_once('connection.php'); if (!$con) { die('Could not connect!' . mysql_error()); } mysql_select_db("$database") or die('Choose a database ' . mysql_error()); And then a $query/$result Can the lines BEFORE the $query go into an INCLUDE file ALSO if they are going to be constant and repeated, or do they have to be hardcoded into each file individually? I get this error when trying to include header.php and sidebar.php Code: [Select] hParse error: syntax error, unexpected '/' in /home/ucherllo/public_html/index.php on line 26 Here are is index.php and includes code. INDEX.PHP Code: [Select] <html> <head> <title>Cher LLoyd - UltimateCherLloyd.net - Your newest fan site for everything Cher Lloyd. News, media, photos, and more. </title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="description" content="Newest fan site for everything Cher Lloyd" /> <meta name="keywords" content="cher lloyd, cher lloyd fansite, cher lloyd x-factor, fansite, fan site, swagger jagger, playa boi, dub on the track, 2010, 2011, cher lloyd photos, cher lloyd news, cher lloyd media, cher lloyd fan site" /> <meta name="author" content="D" <meta name="robots" content="index, follow" /> <!-- PUT THIS TAG IN THE head SECTION --> <script type="text/javascript" src="http://partner.googleadservices.com/gampad/google_service.js"> </script> <script type="text/javascript"> GS_googleAddAdSenseService("ca-pub-7892222271864999"); GS_googleEnableAllServices(); </script> <script type="text/javascript"> GA_googleAddSlot("ca-pub-7892222271864999", "FlauntDarkLeader"); </script> <script type="text/javascript"> GA_googleFetchAds(); </script> <!-- END OF TAG FOR head SECTION --> <link href="style.css" rel="stylesheet" type="text/css"> </head> <?PHP include(/home/ucherllo/public_html/header.php); ?> <td height="265" align="left" valign="top" bgcolor="#FFFFFF"> <?PHP $number=10; include("/home/ucherllo/public_html/news/show_news.php"); ?> </td> <?PHP include(/home/ucherllo/public_html/sidebar.php); ?> SIDEBAR.PHP Code: [Select] <td width="247" align="left" valign="top" bgcolor="#FFFFFF">testing</td> </tr> </table> <!-- End Save for Web Slices --> </body> </html> HEADER.PHP Code: [Select] <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="800" align="center" border="0" cellspacing="0" cellpadding="5"> <tr> <td bgcolor="#FFFFFF"><center><!-- PUT THIS TAG IN DESIRED LOCATION OF SLOT FlauntDarkLeader --> <script type="text/javascript"> GA_googleFillSlot("FlauntDarkLeader"); </script> <!-- END OF TAG FOR SLOT FlauntDarkLeader --></center></td> </tr> </table> <!-- Save for Web Slices (ucherlloyd.psd) --> <table width="801" height="359" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01"> <tr> <td colspan="11"> <img src="images/index_01.png" width="800" height="46" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="46" alt=""></td> </tr> <tr> <td colspan="7"> <img src="images/index_02.png" width="509" height="3" alt=""></td> <td rowspan="2"> <img src="images/index_03.gif" width="24" height="28" alt=""></td> <td colspan="3" rowspan="3"> <img src="images/index_04.png" width="267" height="179" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="3" alt=""></td> </tr> <tr> <td colspan="6" rowspan="3"> <img src="images/index_05.png" width="485" height="271" alt=""></td> <td> <img src="images/index_06.gif" width="24" height="25" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="25" alt=""></td> </tr> <tr> <td colspan="2" rowspan="4"> <img src="images/index_07.png" width="48" height="285" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="151" alt=""></td> </tr> <tr> <td rowspan="3"> <img src="images/index_08.png" width="13" height="134" alt=""></td> <td> <img src="images/index_09.gif" width="241" height="95" alt=""></td> <td rowspan="3"> <img src="images/index_10.png" width="13" height="134" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="95" alt=""></td> </tr> <tr> <td rowspan="2"> <img src="images/index_11.png" width="23" height="39" alt=""></td> <td><a href="index.php"><img src="images/index_12.gif" alt="" width="51" height="22" border="0"></a></td> <td> <img src="images/index_13.gif" width="88" height="22" alt=""></td> <td> <img src="images/index_14.gif" width="71" height="22" alt=""></td> <td> <img src="images/index_15.gif" width="93" height="22" alt=""></td> <td rowspan="2"> <img src="images/index_16.png" width="159" height="39" alt=""></td> <td rowspan="2"> <img src="images/index_17.png" width="241" height="39" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="22" alt=""></td> </tr> <tr> <td colspan="4"> <img src="images/index_18.png" width="303" height="17" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="17" alt=""></td> </tr> </table> <table width="799" border="0" align="center" cellspacing="0" cellpadding="5"> <tr> This is my website http://ucherlloyd.net/ PS: on Index.php there is also a Cutenews include that worked before i included sidebar.php & header.php HELP? Thanks in advance! |