PHP get current user from Active Directory server

IT Tutorials

If you want to write a php program and you want to be able to use the active directory users from you domain you have to include in your page some code :

$cred = explode(‘\\’,$_SERVER[‘REMOTE_USER’]);
if (count($cred) == 1) array_unshift($cred, “(no domain info – perhaps SSPIOmitDomain is On)”);
list($domain, $user) = $cred;

You can use in your database table a “users” row and do a select like :

$query=mysqli_query(select * from users where user=’$user'”);

and then do some stuff

if (mysqli_num_rows($query)>0)
{
echo “xxxxxxx”;
}
else
{
echo “yyyyyyy”;
}

Then you can use the $user variable to gain acces to certain pages or other :

if ($user<>‘xxx’ and $user<>‘yyyy’)
{
header(‘Location:../index.php’);
}
else
{
header(‘Location:../error.php’);
}

I hope this will help !

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet - Rate this article !)
Loading...


Lost Password