Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP
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 20-Feb-13 21:52pm
kavinsp269
Edited 20-Feb-13 23:11pm
v2
Comments
enhzflep at 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 at 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 at 21-Feb-13 7:53am
   
No.. client machine user name
Sandeep Mewara at 21-Feb-13 11:51am
   
Did you try anything?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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>
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 751
1 George Jonsson 330
2 Garth J Lancaster 290
3 Sergey Alexandrovich Kryukov 274
4 BillWoodruff 252
0 Sergey Alexandrovich Kryukov 10,879
1 OriginalGriff 5,555
2 Maciej Los 5,534
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web01 | 2.8.141030.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100