Page 1 of 1

Variables in external PHP Files

Posted: Thu 3. Jun 2004, 18:00
by super ü
Hi there,

i was searching for a solution to retrieve Variables in external PHP Files just like {PHP:my_ext.php?var=1} - there is a function in the forum but it messes up with other php includes.

So i have a very quick and very dirty hack:

In the content Element:

[PHP]
$var = 1
$relocate = "my_external.php"
include(relocate);
[/PHP]


IMPORTANT: 'relocate' is a file without file ending in the wcms root with the following content:

<?
include($relocate);
?>


So now, you have the $var available in my_external.php, and in any other external php file namend in $relocate.


Has Anyone another solution for this?
I tried everything, defining $GLOBALS wont work, but maybe I didn´t get the way PHPVAR works ...

Thank you

Posted: Fri 4. Jun 2004, 09:03
by Oliver Georgi
If you use it that way it can not work.

all vars you are using have to be defined as global vars because all {PHP, {PHPVAR, [PHP is processed in separate functions - so vars you are set there are NON GLOBAL vars.

Vars you want to use anywhere has to be brought to the $GLOBALS array first.

You can try:

Code: Select all

global $myvar;
or

Code: Select all

$GLOBALS['myvar'] = 1;
Oliver