Connect to LDAP

Connect to LDAP

am 09.11.2009 03:00:09 von Ashley

Hi folks,

I've never done any PHP->LDAP code writing (nor have I ever dealt
with an LDAP server to begin with.) However I'm writing an app which
requires verifying a user's credentials against an LDAP server. The
admin of the server sent me the following snippet, however also made it
clear that he is not 100% whether it's accurate (he's not a PHP coder).
And I don't have remote access to the server (the app is going to sit on
the internal network and the LDAP server doesn't accept outside
connections.)

So, asking the wise folks on here, does the following piece look
semantically correct?

/* Check against LDAP server */
$adServer = "server.address.hidden";
$ldapconn = ldap_connect($adServer) or die("Connection to the
AD server failed.");
$ldapuser = $_POST["uname"];
$ldappass = $_POST["pword"];
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);

if ($ldapbind) {
$msg = "User Authenticated Successfully!";
$_SESSION['username'] = $ldapuser;
$_SESSION['password'] = $ldappass;
return true;
} else {
$msg = "Invalid username / password";
return false;
}

Thanks.

-- A

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Connect to LDAP

am 09.11.2009 08:19:16 von Devendra Jadhav

--00163631073be454b30477eb021f
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Yes. Correct

On Mon, Nov 9, 2009 at 7:30 AM, Ashley M. Kirchner wrote=
:

>
> Hi folks,
>
> I've never done any PHP->LDAP code writing (nor have I ever dealt with =
an
> LDAP server to begin with.) However I'm writing an app which requires
> verifying a user's credentials against an LDAP server. The admin of the
> server sent me the following snippet, however also made it clear that he =
is
> not 100% whether it's accurate (he's not a PHP coder). And I don't have
> remote access to the server (the app is going to sit on the internal netw=
ork
> and the LDAP server doesn't accept outside connections.)
>
> So, asking the wise folks on here, does the following piece look
> semantically correct?
>
> /* Check against LDAP server */
> $adServer =3D "server.address.hidden";
> $ldapconn =3D ldap_connect($adServer) or die("Connection to the AD
> server failed.");
> $ldapuser =3D $_POST["uname"];
> $ldappass =3D $_POST["pword"];
> $ldapbind =3D ldap_bind($ldapconn, $ldapuser, $ldappass);
>
> if ($ldapbind) {
> $msg =3D "User Authenticated Successfully!";
> $_SESSION['username'] =3D $ldapuser;
> $_SESSION['password'] =3D $ldappass;
> return true;
> } else {
> $msg =3D "Invalid username / password";
> return false;
> }
>
> Thanks.
>
> -- A
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--=20
Devendra Jadhav
देवेंदॠà¤° =
जाधव

--00163631073be454b30477eb021f--