Re: reading variables in other script files

From: Date: Fri, 01 Aug 2003 09:52:57 +0000
Subject: Re: reading variables in other script files
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-157915@lists.php.net to get a copy of this message
2 ways come to mind - one's messy one isnt! Non-Messy: You could put $var1 into an include file, and include it in both file1.php and file2.php, eg: //Inc.php $var1 = "some value"; //file1.php include('Inc.php'); $var1 == "some value"; //file2.php include('inc.php'); $var1 == "some value"; $var1 will be avaliable in both files. inc.php could, of course have some code in it to set the variable (for example a random number etc). $var1 would also be avaliable to any other scripts that may need it in the future, just by including the inc.php file. Messy: Open file1.php from file2.php and read the variable out of it... ***MESSY, SLOW AND DIRTY*** Craig Roberts "Kalle Saarinen" <kalles@acte.fi> wrote in message news:003201c35811$242b4650$08cba8c0@kalle... > Hello > > I was just wondering how can I get value of a variable in php code located > in a different file? > > ie. > > I have file1.php wich stores $var1 > how can I read the value of $var1 in file2.php > > I have database and I can put it in there (I quess) but is that the only > way? > > -Kalle >

« previous php.general (#157915) next »