[thelist] [fwd] Re: PHP - includes & variable scope problem....

Harrison Dekker harrison at rta-net.com
Thu Aug 2 13:49:01 CDT 2001


---------------------------------------------
This message was held by thelist software and
is being manually forwarded by a list admin.
Please remember to send emails in plain-text
format only, or they will not reach thelist
until it is later forwarded by a list admin.
---------------------------------------------


> The problem is actually simple..... I d like the text in my=20
> includes to access the variables on the MAIN page from where they come =

> from

Is your MAIN page a page containing an include statement? If so, =
included pages will have access to variables defined in MAIN prior to =
the include, assuming of course they weren't defined within a function =
definition.

Or, is your MAIN page a prior page from which you're linking to =
subsequent pages which need to access the variables defined in MAIN? If =
this is the case, you have several options. PHP's "built in" way of =
dealing with this is session variables. Check the documentation for the =
syntax.(see http://www.php.net/manual/en/ref.session.php ). Using =
database queries as you described is also a valid option. (4,5, or 6 =
queries isn't necessarily bad either, but it depends on the size of the =
tables, type of queries, server load etc) You can also put variable into =
HIDDEN form elements or add them to your query string and pass them as =
CGI variables to your next page. I've been using PHP for over two years =
and still use a combination of these methods depending on my mood.

Harrison





More information about the thelist mailing list