I want to access global variable of drupal (like user variable in
drupal) into another php files
I Create a new module for example test module.
my test module have 3 files . test.info , test.module , main.php
I want to use global variable of drupal into main.php as following code

global $user;
please guide me how can i access this drupal variable in my page?
thanks

Comments

hilarudeens’s picture

Hi,
So simple just declare your variable with global keyword in your php file and then initiate your global variable.
Now your global variable available in anywhere in your project until unless you are disable the module.
For example...

<?php
global $myglobal;
$myglobal= 'abc123';
....
....

But More powerful drupal way is,

<?php
function yourmodule_init(){
global $myglobal;
$myglobal= 'abc123';
....
....
}

Note: your main.php should be included in drupal running way....
good luck...,

m2jalali’s picture

i mean global variable of drupal not simple global variable in a php page

hilarudeens’s picture

hi,
If you want to use drupal's or any other global variable in your php file (main.php) i need information about how you include your file (main.php) in any custom/contributed module(test.module)... Need info on these to give respective solution...

thanks,