How can I get the name of the currently logged in user in Drupal 7 in the external file?
I advice you to:


create a module
put your script in that module (inside one or more functions)
implement hook_menu() to define the url you can call (eg. example.com/mytuff/ajax) and set your script's (main) function as the 'page callback'
instead of returning stuff (like page callbacks normally do) print your output and exit() at the end