getting currently logging domain user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sbettadpur
    New Member
    • Aug 2007
    • 121

    getting currently logging domain user

    hello

    i need currently logged in domain user name using php.

    i saw in google there is %USERNAME%

    but i have not getting
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    I think that will be from a GET form that you get that %USERNAME%. Explain a little more. Do you have a login system? So users type in their username and password and you log them in to somewhere? Post what code you do have in correct code tags and explain it a little bit more.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      PHP is a server side language - it will read headers and form
      data sent by the client browser, but it cannot request the data. That kind of information is not transmitted with the HTTP headers.

      If the web server is in the same domain, i.e. intranet, try echoing
      $_SERVER['LOGON_USER'] and $_SERVER['AUTH_USER']. Might only work with IE.

      You might have more success asking in a Windows and/or IIS forum, as to how
      you can get the user name into the server environment.

      Ronald

      Comment

      • sbettadpur
        New Member
        • Aug 2007
        • 121

        #4
        Thanks for reply,

        First let me explain, what my requirement.
        Actually i wrote a script to get users of Active Directory i,e domain users.
        i did above one using ldap_connect functions which is available in php
        using my script i can display all users, but my requirement is once, user is entered
        script has to check, if that user is authenticated or not? if authenticated then fetch email id of that currently logged in user.
        for your reference i am sending my source code[PHP]
        <?php
        error_reporting (0);
        $errorMessage = false;
        //$server = 'ldap://example.ldapser ver.com';
        $server = 'ldap://192.168.0.35';
        $dn = 'dc=ABMSPL-TEST';//'CN=Users,DC=AB MSPL-TEST,DC=com';
        $bind_user = 'srinath@ABMSPL-TEST';
        $bind_pass = 'Welcome123';
        $d = $_SERVER['LOGON_USER'] ;
        echo $d;
        if(isset($_POST['login']))
        {
        $username = $_POST['username'];
        $password = $_POST['password'];
        $ldapconnect = ldap_connect($s erver,389);
        if(!$ldapconnec t)
        {
        $error_message = '<p>error: connection to server failed...</p>';
        }
        else{
        $ldapbind = ldap_bind($ldap connect, $bind_user, $bind_pass);
        if(!$ldapbind){
        $errormessage = '<p>error: binding to server failed...</p>';
        echo "binding failed";
        }
        else{
        $filter = '(samaccountnam e='.$username.' )';
        $ldapsearch = ldap_search($ld apconnect, $dn, $filter);
        if(!$ldapsearch ){
        $errormessage = '<p>error: search on server failed...</p>';
        echo "search failed";
        }
        else{
        echo "search passed";
        $userdetails = ldap_get_entrie s($ldapconnect, $ldapsearch);
        if(!$userdetail s){
        $errormessage = '<p>error: entries not retreived...</p>';
        echo "entries not retreived";
        }
        if($userdetails["count"] == 0){
        $errormessage = '<p>unknown user, please try again.</p>';
        echo "unknown user";
        }
        if($userdetails["count"] > 1){
        $errormessage = '<p>more then one such user. please report to it support</p>';
        echo $errormessage;
        }
        else{
        $info= ldap_get_entrie s($ldapconnect, $ldapsearch);
        $userDetails= ldap_get_entrie s($ldapconnect, $ldapsearch);
        $user_dn = $userDetails[0]["dn"];
        echo $user_dn;
        echo "<table border='1'>";
        for ($i=0; $i<$info["count"]; $i++) {
        print ("<TR>");
        //print ("<TD width=15%>" . $info[$i]["cn"][0] . " " . $info[$i]["sn"][0]
        print ("<TD width=15%>" . $info[$i]["cn"][0] . " " . $info[$i]["sn"][0]. "</TD>");
        print ("<TD width=85%>" . $info[$i]["mail"][0] . "</TD>");
        print ("<TD width=85%>" . $info[$i]["phno"][0] . "</TD>");
        print ("<TD>" . $info[$i]["dn"][0] . "</TD>");
        print ("</TR>");
        }
        echo "</table>";
        //echo "entries retreived";
        //echo $user_dn;
        echo $auth_password;
        $userBind = ldap_bind($ldap Connect, $user_dn, $password);
        if(!$userBind){
        $errorMessage = '<p>Invalid Username/Password!</p>';
        }
        else{
        // Do Something…
        }
        }
        }
        }
        }
        ldap_close($lda pConnect);
        } ?><html>
        <head>
        </head>
        <body>
        <div id="login">
        <h2>login</h2>
        <p>please enter your username and password.</p>
        <form method="post" action="ldap.ph p">
        <p>Username:</p>
        <input type="text" name="username" tabindex="1" />
        <p>Password:</p>
        <input type="password" name="password" tabindex="2" />
        <input type="submit" name="login" value="login" tabindex="3" />
        </form>
        <?php echo $errorMessage;? >
        </div>
        </body>
        </html>
        [/PHP]
        Last edited by ronverdonk; May 2 '08, 03:52 PM. Reason: use the correct code tags in their correct format!!

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          PLEASE!!! Put code tags around your post. Click Edit on your last post and put [PHP ] [/PHP ] (remove spaces) around all that code! Then we will read it.

          Comment

          • mageswar005
            New Member
            • Mar 2008
            • 72

            #6
            hi,
            NTLM authentication should be best way to get domain user name....

            Comment

            Working...