Use php's builtin solution for this:
$username = getenvvar('USERNAME') ;
Or on unix: $username = gettnvvar('LOGNAME') ;