?
Solved

NT User Login Capture

Posted on 2003-03-25
13
Medium Priority
?
13,316 Views
Last Modified: 2012-08-13
Hi,

I was wondering if there is anyway to capture the NT user Login in PHP. The ASP code is Request.ServerVariables("logon_user"), does anyone know if PHP has somethign similar. I am running PHP, Apache and MySQL as my Intranet server and need to capture the login to provide indivual pupils timetables on login (I work for a school).

Thanks for any help,

Paul
0
Comment
Question by:doconline
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 2

Expert Comment

by:ShockwaveRK
ID: 8201968
Paul,

Login to a website and call the function phpinfo(); in a script. When you find your username in the output you will also find the variable that has your value in it. If not it is not stored in the server vars of your php.

--
Greetz,
Robert, The Netherlands.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8202080
Something you could try is adding a line to the NT login script which creates an environment variable with their name.

SET WHOAMI=%USERNAME%

or something similar.

Then, you could use $_ENV['WHOAMI'];

Not very secure, but you could put an encrypted output for the name.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8202676
huh ?!?

I thought $_ENV[] was server-side ?
0
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8202882
Doh!

Of course!

Erm.

He he!

0
 
LVL 1

Expert Comment

by:Kriek
ID: 8203439
PHP does not support NTLM authentication. ASP does, Java does, Perl does, Python does, but PHP don't =)

However you might try this:

<?php
echo "Your username is: ".$_SERVER["AUTH_USER"];
echo "<br>";
echo "The authentication type is: ".$_SERVER["AUTH_TYPE"];
echo "The digest of your password is: ".$_SERVER["HTTP_AUTHORIZATION"];
echo "<br>";
echo "The username of the server user is: ".$_SERVER["LOGON_USER"];
?>

This will only work under IIS, for Apache you will need to install a additional module (mod_ntlm).
0
 
LVL 1

Expert Comment

by:Kriek
ID: 8203465
PHP does not support NTLM authentication. ASP does, Java does, Perl does, Python does, but PHP don't =)

However you might try this:

<?php
echo "Your username is: ".$_SERVER["AUTH_USER"];
echo "<br>";
echo "The authentication type is: ".$_SERVER["AUTH_TYPE"];
echo "The digest of your password is: ".$_SERVER["HTTP_AUTHORIZATION"];
echo "<br>";
echo "The username of the server user is: ".$_SERVER["LOGON_USER"];
?>

This will only work under IIS, for Apache you will need to install a additional module (mod_ntlm).
0
 
LVL 1

Expert Comment

by:Kriek
ID: 8203486
So techically NTLM authentication "is" possible with PHP assuming

A) you run it on a NT/2000/.NET box,

B) IIS is used.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8203657
well, there is also the solution of using the HTTP Basic Authentication, or to use cookies...

OR (and this is the best solution), and BECAUSE you know that your customers willcome from a soecific network (so that you've their NT login, for example an Intranet) :
-give each and every client (for example free or automatic download on some index.html page of your site) a small program that runs in the background on their NT box and sends NT auth data along with @IP to the server, thus enabling him to "recognize" the people being connected from the $REMOTE_ADDR afterwards.
At least that's what I would do if I were you 8-)
0
 
LVL 14

Accepted Solution

by:
psadac earned 300 total points
ID: 8205454
If all your clients are netbios enabled (generally true) and you just need the username and station, this should help you :

<?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"];
    }
    echo 'ip : '.$ip.'<br>';
   
    /* 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 */
    echo '<table border="1">';
    echo '<tr><th>no</th><th>type</th><th>value</th></tr>';
    for($i = 0; $i < $nbrec; $i++) {
     $offset = 18 * $i;
     printf ("<tr><td>%02d</td><td>%02X</td><td>%s</td></tr>",
         $i,
         ord($data[72 + $offset]),
         trim(substr($data, 57 + $offset, 15)));
    }
    echo '</table>';
?>
0
 
LVL 15

Expert Comment

by:VGR
ID: 8205562
hack hack hack hack

wonderful 8-)
0
 
LVL 15

Expert Comment

by:VGR
ID: 8209091
So it works ? :D
How amazing :D
It wouldn't work for my machine, I closed those silly ports 8-)
0
 
LVL 14

Expert Comment

by:psadac
ID: 8210130
Of course it works, and it's not a hack, it's just netbios that works this way.
special thanks to snort (http://www.snort.org :)
0
 
LVL 3

Expert Comment

by:Timothy Golden
ID: 12059260
psadac,

so how can i use this?

I want to look at the user name and set it to a varialbe then do a few if/then  statements with the variable

How do i set the user name to a variable?

0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question