I've read on tutorial web sites that if you set a variable in a file and the include another file that references that variable, it'll work, but it isn't working for me. Here's an example of my code: http://www.mysite.com/folder/thisfile.php <?php $testvariable = "test"; include("http://www.mysite.com/test.php"); ?> PHP: http://www.mysite.com/test.php <?php echo "Output: ". $testvariable; ?> PHP: And the page only says "Output: " Could it be because it's including a file that's not in the same folder? I don't understand why it's not working. Any help would be appreciated!
You are doing it wrong. try this http://www.mysite.com/folder/thisfile.php <?php $testvariable = "test"; ?> PHP: http://www.mysite.com/test.php <?php include("folder/thisfile.php"); echo "Output: ". $testvariable; ?> PHP:
That won't allow me to do what I'm trying to do though. I want to have several folders with a file that all include the 'test.php' file, but with a different variable. If that's not possible, then I guess I'll have to go back to the drawing board and figure out a different way to accomplish what I'm trying to do.
You can rather define the variable instead. // folder/thisfile.php <?php define('TESTVARIABLE', 'test'); include '../test.php'; ?> // test.php <?php echo defined('TESTVARIABLE') ? TESTVARIABLE : 'TESTVARIABLE not found...'; ?> PHP: