Variables in external PHP Files

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
super ü
Posts: 6
Joined: Wed 28. Apr 2004, 12:47

Variables in external PHP Files

Post 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
----------------
mfg
User avatar
Oliver Georgi
Site Admin
Posts: 9920
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post 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
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Post Reply