behaviors javascript executing
Difficult to separate your php from javascript, but if you set js variable with this php code it should execute first and can be used within leaflet js function later:

&lt;?php render('&lt;script&gt;var username = "'.$GLOBALS['user'].'";&lt;/script&gt;'); ?&gt;