I think the problem is the require line for global.php. Because of the way global.php is written, you need to do something like:
Code:
$savedir = getcwd ();
chdir('/path/to/forum/');
require_once('global.php');
chdir($savedir);
Also, if your code is inside a function it causes other problems, because variables that are supposed to be global won't be. If that's true for you, you could solve that by declaring some other variables as global before including global.php (I can't remember which ones offhand).