mrs_spence Posted March 2, 2009 Share Posted March 2, 2009 Hello all! I'm hoping you will be able to help me, I've built a templated site using dreamweaver, so it's a bit clunky. I'm using very 3 x very simple include functions on each page to call the navigation file on the left, a footer file on the bottom, and a teaser navigation menu on the right of each page. Problem is, now I want to include a print version, which I have a snippet of code for in PHP. But as this is placed in the content section of the page, it's second on the list of functions to be called. The first function, include <?php include_once "http://www.mydomain.net/development/nav.php";?> is always called first, which prevents my print friendly php document at http://www.mydomain.net/development/pfv.php from loading anything. Obviously, 'cos it's trying to load another file altogether! In order to resolve this problem, could I specify some javascript or similar in the body onload function? I'm a real newbie to coding, so any help is really appreciated. Thanks Mrs_Spence Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/ Share on other sites More sharing options...
genericnumber1 Posted March 2, 2009 Share Posted March 2, 2009 I'm not going to pretend I understood what your problem is, but could it be that you mean to be including locally and you're including remotely? Try including the file like this: <?php include_once "path/to/nav.php";?> Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-774393 Share on other sites More sharing options...
WolfRage Posted March 2, 2009 Share Posted March 2, 2009 Lets see the script for 1, and 2: genericnumber1 is right about including externally, which also slows down your page processing. 3: I think you are confusing the difference of including a function and including another script. 4: Seeing the code will let us beter determine your particular problem(s). In the long run it will only help you. Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-774496 Share on other sites More sharing options...
mrs_spence Posted March 2, 2009 Author Share Posted March 2, 2009 Oh my, what should I include? the whole page of code, or just the four instances? I'm so new to this caper, as you can tell. Thanks for your patience. Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-774570 Share on other sites More sharing options...
phpdragon Posted March 2, 2009 Share Posted March 2, 2009 could you post us some code of what you have done or trying, we may be able to help a little better then, to understand what you are asking Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-774651 Share on other sites More sharing options...
mrs_spence Posted March 3, 2009 Author Share Posted March 3, 2009 Ok, here goes!! Index.php file has three separate instances of included pages when it loads in the browser. 1 - <?php include_once "../nav.php";?> (this is the nav of the page on the left) 2 - <?php include_once "../header.htm";?> (this is the header at top of page) 3 - <a href="pfv.php"> (this is the 'print' function) 4 - <?php include_once "../footer.htm";?> (this is the footer included on the page) <!-- CONTENT --> and <!-- /CONTENT --> tags specify body text to be printed. In terms of load order on the page, the browser would load this fifth or sixth down the line. OK. Number 3 is reference to a 'print friendly' version file called pfv.php. Whenever the user clicks 'print', of course the entire page of code is sent to pfv.php with links to 1 and 2 getting in the way and preventing any of the body text being sent to the pfv.php page. I'm assuming it's causing some sort of loop to occur. How can I make the pfv.php page load without the references to the first two files? Can I specify some sort of load order, specifying that 3 is loaded using an onload function or similar? Thanks Mrs Spence Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-775246 Share on other sites More sharing options...
genericnumber1 Posted March 3, 2009 Share Posted March 3, 2009 Assuming I understand what you mean, you wish to include nav.php and header.php only if the user is not viewing the print friendly version? In that case, something like this would suffice... page.php: <?php if(!isset($_GET['printer_version']) || $_GET['printer_version'] != true) { include_once "../nav.php"; include_once "../header.htm"; } ?> <a href="page.php?printer_version=true">Printer friendly version</a><br /> <a href="page.php">Non-Printer friendly version</a> <?php include_once "../footer.htm"; ?> I'd also advise switching from include_once to require_once if it's a very important file. Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-775250 Share on other sites More sharing options...
WolfRage Posted March 3, 2009 Share Posted March 3, 2009 Of course make note that using require will result in a fatal error if the file is not included, which can spit out a error message that will give away your server's file structure, to eliminate this you can use include and then check for a variable that is defined in the included file and if the variable does not exist then you know the file was not included and you can use your own error handling procedures. Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-775256 Share on other sites More sharing options...
genericnumber1 Posted March 3, 2009 Share Posted March 3, 2009 Well, to be fair, when include fails an error message will still be displayed, it just won't be fatal. Checking flag variables in included files is a bit messy for me, I prefer to just use some of the error functions such as set_error_handler to define my own error handling procedures. Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-775264 Share on other sites More sharing options...
WolfRage Posted March 3, 2009 Share Posted March 3, 2009 Right, I understand. But I don't have my production machine setup to display errors that are non-fatal. Also you can supress those further with "@". Quote Link to comment https://forums.phpfreaks.com/topic/147511-multiple-instances-of-php-include-function-on-one-page/#findComment-775269 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.