I am trying to pass a variable to an include file. My host has changed the version of PHP, and now any solution I'm trying to make does not work.
I think I tried everything I could find. I am sure this is the easiest thing!
The variable should be set and evaluated from the first calling file (this is actually $_SERVER['PHP_SELF'] , and it needs to return the path to this file, and not the second.php included).
OPTION ONE
In the first file:
global $variable; $variable = "apple"; include('second.php');
In the second file:
echo $variable;
OPTION TWO
In the first file:
function passvariable(){ $variable = "apple"; return $variable; } passvariable();
OPTION THREE
$variable = "apple"; include "myfile.php?var=$variable"; // and I tried with http: and full site address too. $variable = $_GET["var"] echo $variable
None of them work for me. The PHP version is 5.2.16.
What am I missing?
Thank!
variables include php global-variables global
user1590646 Aug 10 '12 at 15:50 2012-08-10 15:50
source share