Re: Passing Variables and the include command

From: Date: Wed, 19 Sep 2001 05:36:48 +0000
Subject: Re: Passing Variables and the include command
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-67791@lists.php.net to get a copy of this message
Included files share the same global symbol table as the parent file. So, simply do: $file = "somefile.txt"; include "counter.php"; And by the way, please don't use "$file". It makes no sense. Just $file. -Rasmus On Tue, 18 Sep 2001, Andrew V. Romero wrote: > I was wondering if it is possible to pass some variables to a php file > that will be accessed via the include command? For example, I am > working on creating a nicer "hits" counter and would like to just write > the code for the counter once and then have each page access that > counter.php3 and pass a variable which would contain the page name to > counter.php3 so counter.php3 could write the new counter to a file with > the pageName.log. Right now I am using a very simple counter: > -counter.php3- > $file = "interest"; > $counterFile=fopen("$file".".log","r"); > $counterRecord = trim( fgets($counterFile, 4096) ); > fclose($counterFile); > $counterRecord++; > $counterFile = fopen("$file".".log", "w"); > fwrite($counterFile,"$counterRecord"); > fclose($counterFile); > > Ideally, I would like to have each of my pages call counter.php3 using > the include command and have the page pass it the variable $file. Any > ideas? > > Thanks, > Andrew V. Romero > > >

« previous php.general (#67791) next »