473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

getting currently logging domain user

121 100+
hello

i need currently logged in domain user name using php.

i saw in google there is %USERNAME%

but i have not getting
Apr 28 '08 #1
5 9345
TheServant
1,168 Expert 1GB
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.
Apr 28 '08 #2
ronverdonk
4,258 Expert 4TB
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
Apr 28 '08 #3
sbettadpur
121 100+
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.ldapserver.com';
$server = 'ldap://192.168.0.35';
$dn = 'dc=ABMSPL-TEST';//'CN=Users,DC=ABMSPL-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($server,389);
if(!$ldapconnect)
{
$error_message = '<p>error: connection to server failed...</p>';
}
else{
$ldapbind = ldap_bind($ldapconnect, $bind_user, $bind_pass);
if(!$ldapbind){
$errormessage = '<p>error: binding to server failed...</p>';
echo "binding failed";
}
else{
$filter = '(samaccountname='.$username.')';
$ldapsearch = ldap_search($ldapconnect, $dn, $filter);
if(!$ldapsearch){
$errormessage = '<p>error: search on server failed...</p>';
echo "search failed";
}
else{
echo "search passed";
$userdetails = ldap_get_entries($ldapconnect,$ldapsearch);
if(!$userdetails){
$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_entries($ldapconnect, $ldapsearch);
$userDetails= ldap_get_entries($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($ldapConnect, $user_dn, $password);
if(!$userBind){
$errorMessage = '<p>Invalid Username/Password!</p>';
}
else{
// Do Something…
}
}
}
}
}
ldap_close($ldapConnect);
} ?><html>
<head>
</head>
<body>
<div id="login">
<h2>login</h2>
<p>please enter your username and password.</p>
<form method="post" action="ldap.php">
<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]
Apr 29 '08 #4
TheServant
1,168 Expert 1GB
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.
Apr 29 '08 #5
hi,
NTLM authentication should be best way to get domain user name....
Apr 29 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Michelle Stone | last post by:
Hi everybody I am writing a simple asp.net application using form authentication. I store the list of all users and their passwords in an SQL Server database table. My client recently told me...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
7
by: Oenone | last post by:
Sorry for the cross-post but I've really no idea where this is best suited. I've an ADO.NET application which connects to a SQL Server database. I have spent the entire morning trying to get it...
11
by: Derek Martin | last post by:
Using VB.Net, I would like to retrieve the currently logged in user's DN from Active Directory. Alternatively, if, using WindowsIdentity, or something similar, I would like to get the user's full...
2
by: Scott M. Lyon | last post by:
I'm having some strange problems with a VB.NET application that I support. The application currently uses SystemInformation.UserName() and SystemInformation.UserDomainName() to determine who is...
4
by: Odd Bjørn Andersen | last post by:
I have installed DB2 9 Enterprise Edition on my laptop (Windows xp prof. ed.). But when I try to connect to any of my local databases I get this error: SQL30082N Security processing failed with...
8
by: simonlpwaters | last post by:
I need to obtain the username of the currently logged in user on a machine. However, the program that needs to do this will be running under different credentials to the logged in user, so using...
0
by: Per0 | last post by:
Hi, I have problem getting all domains. My code looks like: _dirEntry.Path = "LDAP://RootDSE" _strRootDomain = "LDAP://" & _dirEntry.Properties("rootDomainNamingContext").Value.ToString()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.