You could try with a setter/getter function declared once in the global scope, but it doesn't do much more than accessing GLOBALS anyway.
function globalUid($value = False)
{
GLOBAL $__uid;
if (!isset($__uid))
$__uid = False;
if (False === $value)
return $__uid;
$__uid = $value;
}
Then instead of echoing $uid
, try globalUid($uid)
and, later, $saved_uid = globalUid();
.
But I think it's possible the two scopes are executing across two different calls, so you might need to save the UID in the session variables.