Get username of logged in user in os via browser
is this possible or not?
Definitely not in a way that is compatible with all browsers on all operating systems.
Nope, that would be somewhat of an invasion of privacy. You need to ask the user for that information on your website using a form.
Check your web server configuration documentation. With many of them, you can enable authentication that integrates with your domain or LDAP services, Kerberos and similar. This may well allow you to do the kind of "single sign-on" you're talking about, at least with browsers that support the method you choose (and this being intranet, presumably you can constrain browser choice a bit — at least for convenience features like not having to log in again). Once authenticated, you should have the username or similar available.
You can only do that if you're both (server and client) authenticating against the same authentication host (or hosts that are allied), which is what keeps this from being a privacy nightmare — this is an intranet thing.
You may want to drop a question over at serverfault.com listing your server software, server operating environment, and the browsers you want to support, and see if anyone can help you with single sign-on.
精彩评论