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.


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

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to