How to get NT login with PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • selecto
    New Member
    • Nov 2006
    • 3

    How to get NT login with PHP

    Hi,

    I am struggling since weeks now to find the way to get the NT login of the user connected to a page. We are a group using an intranet with Windows NT and we use PHP for some applications.

    Question is what is the way to get in a variable the NT login, to create a session or a cookie for example, without having to ask for login data again, since the user is already logged in?

    Thanks in advance
  • Midgard
    New Member
    • Nov 2006
    • 10

    #2
    You can use this code.

    [PHP]
    <?php
    // Coded and Designed by Midgard ( bahadir [at] eggdrop [dot] gen [dot] tr )
    // Login

    $auth = false;

    if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
    $username = $_SERVER['PHP_AUTH_USER'];
    $password = md5($_SERVER['PHP_AUTH_PW']);
    $sorgu = sprintf("SELECT * FROM cms_admins WHERE username = '%s' AND password = '%s';", $username, $password);
    $sonuc = mysql_query($so rgu);
    $num = mysql_num_rows( $sonuc);
    if ($num != 0) {
    $auth = true;
    }
    }

    if (!$auth) {
    header('WWW-Authenticate: Basic realm="Please Login!"');
    header('HTTP/1.0 401 Unauthorized');
    echo '<b style="font-family: Century Gothic, Trebuchet MS, Tahoma, Verdana, Arial, helvetica, sans-serif; font-size: 11px; color: red;">Access Denied!</b>';
    exit;
    }
    ?>
    [/PHP]

    Comment

    • selecto
      New Member
      • Nov 2006
      • 3

      #3
      Thanks, but this is not what I wanted. I actually want to get the WINDOWS NT login.

      These are username and password to start a computer in a company network for example.
      In other words, the username (NT Login) is stored temporarily on the computer, and not in any Database

      Cheers

      Comment

      • swandi
        New Member
        • Nov 2006
        • 13

        #4
        Do you mean as PIDEL\if0407? or LKNW\administra tor?
        I think thats a good idea...
        Any one wanna help us, please...

        Comment

        • selecto
          New Member
          • Nov 2006
          • 3

          #5
          I found this code, it says it should work, but for me it returns the value: 0040, whereas it should return my name, as the person logged into this computer.

          Code:
          <?php
              /*
               Getting netbios info
               CopyLeft 2002 (GNU GPL V2) by polo
              */     
              
              error_reporting(E_ALL);
              
              /* get the ip of the client */
              if (isset($_SERVER
          ["HTTP_X_FORWARDED_FOR"]))
           {
               $ip = $_SERVER
          ["HTTP_X_FORWARDED_FOR"];
              } else {
               $ip = $_SERVER["REMOTE_ADDR"]; 
              }    
              /* send a "special" packet */
              $fp = fsockopen('udp://'.$ip, 137);
              fwrite($fp, "\x80b\0\0\0\1\0\0\0\0\0\0 
          CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\0\0!\0
          \1");
          
              /* wait 2 secs, and get the data */
              socket_set_timeout($fp, 2);
              $data = fread($fp, 256);
              
              /* get netbios records number */
              $nbrec = ord($data[56]);
              
              /* display nebios records : the username is 
          a record of type 3 */
             for($i = 3; $i <=3; $i++) {
               $offset = 18 * $i;
          echo ("your login is:");
          printf ("%02d  %02X %s",$i,ord($data[72 + 
          $offset]),trim(substr($data, 57 + $offset, 15)));
          ?>
          any idea on this?

          Comment

          • ethan
            New Member
            • Mar 2014
            • 1

            #6
            No go....

            I worked out the errors here, but it doesn't actually return an NT login for me... It just returns, "Your login is:03 00."

            Code:
            <?php
                 /*
                  Getting netbios info
                  CopyLeft 2002 (GNU GPL V2) by polo
                 */     
             
                 error_reporting(E_ALL);
             
                 /* get the ip of the client */
                 if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
            		{
            			 $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
            		} 
            	 else 
            		{
            			$ip = $_SERVER["REMOTE_ADDR"]; 
            		}    
                 /* send a "special" packet */
                 $fp = fsockopen('udp://'.$ip, 137);
            		 fwrite($fp, "\x80b\0\0\0\1\0\0\0\0\0\0 
            	 CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\0\0!\0
            	 \1");
             
                 /* wait 2 secs, and get the data */
                 socket_set_timeout($fp, 2);
                 $data = fread($fp, 256);
             
                 /* get netbios records number */
                 $nbrec = ord($data[56]);
             
                 /* display nebios records : the username is 
             a record of type 3 */
                for($i = 3; $i <=3; $i++) {
                  $offset = 18 * $i;
            	  
             echo ("your login is:");
             printf ("%02d  %02X %s",$i,ord($data[72 + 
             $offset]),trim(substr($data, 57 + $offset, 15)));
             }
             ?>



            Originally posted by selecto
            I found this code, it says it should work, but for me it returns the value: 0040, whereas it should return my name, as the person logged into this computer.

            Code:
            <?php
                /*
                 Getting netbios info
                 CopyLeft 2002 (GNU GPL V2) by polo
                */     
                
                error_reporting(E_ALL);
                
                /* get the ip of the client */
                if (isset($_SERVER
            ["HTTP_X_FORWARDED_FOR"]))
             {
                 $ip = $_SERVER
            ["HTTP_X_FORWARDED_FOR"];
                } else {
                 $ip = $_SERVER["REMOTE_ADDR"]; 
                }    
                /* send a "special" packet */
                $fp = fsockopen('udp://'.$ip, 137);
                fwrite($fp, "\x80b\0\0\0\1\0\0\0\0\0\0 
            CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\0\0!\0
            \1");
            
                /* wait 2 secs, and get the data */
                socket_set_timeout($fp, 2);
                $data = fread($fp, 256);
                
                /* get netbios records number */
                $nbrec = ord($data[56]);
                
                /* display nebios records : the username is 
            a record of type 3 */
               for($i = 3; $i <=3; $i++) {
                 $offset = 18 * $i;
            echo ("your login is:");
            printf ("%02d  %02X %s",$i,ord($data[72 + 
            $offset]),trim(substr($data, 57 + $offset, 15)));
            ?>
            any idea on this?

            Comment

            Working...