Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/191837-variable-before-include/
Share on other sites

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)

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.