Click here to Skip to main content
12,300,021 members (53,314 online)
Rate this:
 
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 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

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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160525.2 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2016
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