steveangelis Posted February 12, 2010 Share Posted February 12, 2010 As per all of my botcheries of coding, I am attempting to do something that does not want to work. $report_info = include("srs/".$_POST['report_types'].".php"); Now because of how the pages are setup, the variable must be before the include in this manner. What I want is for the include to be, well, included when the variable is called up. For instance, the $_POST['report_types'] comes from another page, and when that variable is loaded onto the next page, that line of code is used. Once the variable is called up later in the page, I need the page to be included to be displayed. If it makes sense to anyone, does anyone know why it is not working? The page is being included at the top of the page where this line of code is. Quote Link to comment https://forums.phpfreaks.com/topic/191837-variable-before-include/ Share on other sites More sharing options...
sader Posted February 12, 2010 Share Posted February 12, 2010 include is not a function is a statement so it doesnt return anything. include works like this lets say this is your index.php <?php $GLOBAL_VAR = 13; include("another.php"); echo $GLOBAL_VAR; ?> now let's say another.php looks like this echo "Hello!!!<br />"; $GLOBAL_VAR = $GLOBAL_VAR + 2; ouput of index.php will be Hello!!! 15 u can imagine include as u would copy and paste peace of code bu remember it doesn return content of that file(use file_get_contents in those cases) Quote Link to comment https://forums.phpfreaks.com/topic/191837-variable-before-include/#findComment-1011126 Share on other sites More sharing options...
premiso Posted February 12, 2010 Share Posted February 12, 2010 Sader is correct, however, if you do want the "output" from an included file returned in a variable you can use output buffering: ob_start(); include("srs/".$_POST['report_types'].".php"); $report_info = ob_end_clean(); Would do it, however, I highly suggest against calling files with include like you have. It is a security risk. Quote Link to comment https://forums.phpfreaks.com/topic/191837-variable-before-include/#findComment-1011129 Share on other sites More sharing options...
teamatomic Posted February 12, 2010 Share Posted February 12, 2010 ob_end_clean will give boolean output. Wont work that way. This will: ob_start(); include("$file"); $output = ob_get_clean();// echo "$output"; HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/191837-variable-before-include/#findComment-1011136 Share on other sites More sharing options...
steveangelis Posted February 12, 2010 Author Share Posted February 12, 2010 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/191837-variable-before-include/#findComment-1011139 Share on other sites More sharing options...
premiso Posted February 12, 2010 Share Posted February 12, 2010 Yea, I meant get_clean, thanks for correcting me teamatomic for pointing that out. Quote Link to comment https://forums.phpfreaks.com/topic/191837-variable-before-include/#findComment-1011172 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.