Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, i need php or js code to get the username of logged in user of the system. when we hit the url of the code it should take the username from the system and display it on web page.
Thanks & regards
kavin
Posted
Updated 20-Feb-13 23:11pm
v2
Comments
enhzflep 21-Feb-13 4:13am    
What did google tell you when you asked it? (you can't get this info with either of those, btw)
Bala Selvanayagam 21-Feb-13 5:18am    
When you say username, are you referring to the username of the server under which the web server is running ?
kavinsp 21-Feb-13 7:53am    
No.. client machine user name
Sandeep Mewara 21-Feb-13 11:51am    
Did you try anything?

1 solution

The following will work, but probably only on IE (with an appropriate ActiveX warning)
<html>
<head>
    <script language="javascript">
        function GetUserName()
        {
            var wshell = new ActiveXObject("WScript.Shell");
            alert(wshell.ExpandEnvironmentStrings("%USERNAME%"));
        }
    </script>
</head>
<body onload="GetUserName();">
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900