<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>david schultz dot org &#187; ldap</title>
	<atom:link href="http://www.davidschultz.org/category/ldap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidschultz.org</link>
	<description>(dot com was taken)</description>
	<lastBuildDate>Thu, 29 Jul 2010 18:23:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to authenticate against Active Directory using PHP</title>
		<link>http://www.davidschultz.org/2008/04/10/how-to-authenticate-against-active-directory-using-php/</link>
		<comments>http://www.davidschultz.org/2008/04/10/how-to-authenticate-against-active-directory-using-php/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 15:09:23 +0000</pubDate>
		<dc:creator>David Schultz</dc:creator>
				<category><![CDATA[active directory]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.davidschultz.org/2008/04/10/how-to-authenticate-against-active-directory-using-php/</guid>
		<description><![CDATA[If you are like most companies out there, your IT department probably has everyone signing on to a Microsoft Active Directory domain. Wouldn&#8217;t it be nice to support single sign on, avoid all those seperate username/passwords littered across your intranet &#038; save yourself some database programming? Here&#8217;s how. First things first, you&#8217;ll need to make [...]

<h3>Related Posts:</h3>
<ol>
		<li><a href="http://www.davidschultz.org/2009/07/06/tutorial-iphone-twitter-push-notifications-using-tweetie/" rel="bookmark">Tutorial: iPhone twitter push notifications using Tweetie</a><!-- (6.45347)--></li>
		<li><a href="http://www.davidschultz.org/2008/03/04/how-to-setup-a-static-route-in-osx-leopard/" rel="bookmark">How to setup a static route in OSX Leopard</a><!-- (5.58784)--></li>
		<li><a href="http://www.davidschultz.org/2008/04/11/pick-of-the-week-tripitcom/" rel="bookmark">Pick of the week: tripit.com</a><!-- (5.28942)--></li>
	</ol>
]]></description>
			<content:encoded><![CDATA[<p>If you are like most companies out there, your IT department probably has everyone signing on to a <a href="http://en.wikipedia.org/wiki/Active_Directory">Microsoft Active Directory</a> domain.  Wouldn&#8217;t it be nice to support single sign on, avoid all those seperate username/passwords littered across your intranet &#038; save yourself some database programming?   Here&#8217;s how.  </p>
<p>First things first, you&#8217;ll need to make sure you have LDAP support installed.  You can double check this by creating a php info page:<br />
<code><br />
echo phpinfo();<br />
</code><br />
<img src="http://farm4.static.flickr.com/3117/2403576964_a272f3d4a9.jpg?v=0" alt="" /></p>
<p>If you run this page &#038; see the LDAP support in there, you are good to go.  If not, you&#8217;ll need to recompile PHP with ldap support by adding the <em>&#8211;with-ldap[=DIR]</em> option to the configure options.  For sake of brevity i&#8217;ll assume you understand how to make an HTML login form.  Once you have created this, you will want to capture the username &#038; password that the user submits.  Now you&#8217;ll need to connect to the ldap server:</p>
<p><code><br />
session_start(); #make sure this is at the top of your PHP file.<br />
$adServer = "127.0.0.1"; #replace with your AD server ip/hostname<br />
$ldapconn = ldap_connect($adServer)<br />
	or $this->msg = "Could not connect to LDAP server.";</p>
<p></code></p>
<p>Now that we&#8217;re connected, you can attempt to authenticate the username/password submitted, which will return a boolean value:</p>
<p><code><br />
$ldaprdn = $adServer . "\\" . $_POST["email"];<br />
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $_POST["password"]);<br />
</code><br />
<code><br />
if ($ldapbind) {<br />
	$msg = "Successfully Authenticated";<br />
	$_SESSION['email'] = $email;<br />
	$_SESSION['password'] = $password;<br />
	return true;<br />
} else {<br />
	$msg = "Invalid email address / password";<br />
	return false;<br />
}<br />
</code></p>
<p>Now that you have stored the authenticated username/password in the users session data, you just need to run this same script before each page loads as you would with mysql user authentication.</p>
<p>From my experience, half the battle was getting my app to talk to the AD server, so best to be clear with your IT guys as to what you are attempting &#038; what you need to minimize frustration .  This was a pretty quick overview, so if you have any questions feel free to drop a comment and i will be happy to help.  You can also check out the <a href="http://ca3.php.net/manual/en/ref.ldap.php">great documentation</a> @ php.net.  </p>


<h3>Related Posts:</h3>
<ol>
		<li><a href="http://www.davidschultz.org/2009/07/06/tutorial-iphone-twitter-push-notifications-using-tweetie/" rel="bookmark">Tutorial: iPhone twitter push notifications using Tweetie</a><!-- (6.45347)--></li>
		<li><a href="http://www.davidschultz.org/2008/03/04/how-to-setup-a-static-route-in-osx-leopard/" rel="bookmark">How to setup a static route in OSX Leopard</a><!-- (5.58784)--></li>
		<li><a href="http://www.davidschultz.org/2008/04/11/pick-of-the-week-tripitcom/" rel="bookmark">Pick of the week: tripit.com</a><!-- (5.28942)--></li>
	</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.davidschultz.org/2008/04/10/how-to-authenticate-against-active-directory-using-php/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.585 seconds -->
