That condition regarding usergroups is correct if it were in a template, but in a php page you would use:
PHP Code:
if (is_member_of($vbulletin->userinfo, 5))
(And I don't understand your other code.... if no userid, then you set the $username to the vbulletin username... but if there is no userid, then there is no username, so I don't understand what you are trying to do. And you have no parenthesis which makes it harder to read cuz I'm assuming there should be some there?)