<?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>sam j levy</title>
	<atom:link href="http://samjlevy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://samjlevy.com</link>
	<description></description>
	<lastBuildDate>Wed, 02 May 2012 05:22:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Ruby on Rails thin server error: `to_specs&#8217;: Could not find thin</title>
		<link>http://samjlevy.com/2012/05/ruby-on-rails-thin-server-error-to_specs-could-not-find-thin/</link>
		<comments>http://samjlevy.com/2012/05/ruby-on-rails-thin-server-error-to_specs-could-not-find-thin/#comments</comments>
		<pubDate>Tue, 01 May 2012 22:45:45 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[Error]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rvm]]></category>
		<category><![CDATA[thin server]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1547</guid>
		<description><![CDATA[When using the /etc/init.d/thin script to run thin server as a service, I experienced the following error: /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find thin (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError) from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec' from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem' from &#8230; <a href="http://samjlevy.com/2012/05/ruby-on-rails-thin-server-error-to_specs-could-not-find-thin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When using the /etc/init.d/thin script to run thin server as a service, I experienced the following error:</p>
<p><code>/home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find thin (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)<br />
    from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'<br />
    from /home/myuser/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'<br />
    from /home/myuser/.rvm/gems/ruby-1.9.3-p125/bin/thin:18:in `<main>'</code></p>
<p>The problem is that the script is trying to start thin without rvm being loaded into shell.</p>
<p>My solution was to replace the default /etc/init.d/thin with this, which first declares the rvm_path and loads rvm into shell:</p><pre class="crayon-plain-tag">#!/bin/bash

# NOTE: script was written for an environment where rails is installed in the user's home directory
# you may need to adjust for your environment

export HOME=&quot;/home/myuser&quot; # path to the user's home directory
export rvm_path=&quot;$HOME/.rvm&quot; # path to RVM
export APP_PATH=&quot;$HOME/myapp&quot; # path to your rails application
export CONFIG_PATH=&quot;$APP_PATH/config/thin.yml&quot; # path to your thin yml
export RUBY_VER=&quot;1.9.3&quot; # desired ruby version

[[ -s &quot;$HOME/.rvm/scripts/rvm&quot; ]] &amp;&amp; source &quot;$HOME/.rvm/scripts/rvm&quot; # load rvm into shell

cd $APP_PATH # navigate to rails app
rvm use $RUBY_VER # select desired ruby version

# using rvmsudo since ports privileged ports (&lt; 1024) require su

case &quot;$1&quot; in
  start)
        rvmsudo thin start -C $CONFIG_PATH
        ;;
  stop)
        rvmsudo thin stop
        ;;
  restart)
        rvmsudo thin restart -C $CONFIG_PATH
        ;;
  *)
        echo &quot;Specify {start|stop|restart}&quot; &gt;&amp;2
        exit 3
        ;;
esac

:</pre><p></p>
<p><strong>Resources:</strong></p>
<ul>
<li><a href="http://articles.slicehost.com/2008/5/6/ubuntu-hardy-thin-web-server-for-ruby" target="_blank">Installing thin on Ubuntu</a></li>
<li><a href="http://stackoverflow.com/questions/10390040/cant-start-thin-server-as-service-rubygems-could-not-find-thin" target="_blank">Stackoverflow &#8211; Can&#8217;t start thin server as service, RubyGems: Could not find thin</a></li>
<li><a href="http://www.debuntu.org/how-to-manage-services-with-update-rc.d" target="_blank">How-To: Managing services with update-rc.d</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2012/05/ruby-on-rails-thin-server-error-to_specs-could-not-find-thin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrade to Ubuntu 12.04 &#8211; Ruby on Rails gem mysql2 error: libmysqlclient_r.so.16</title>
		<link>http://samjlevy.com/2012/04/upgrade-to-ubuntu-12-04-ruby-on-rails-gem-mysql2-error-libmysqlclient_r-so-16/</link>
		<comments>http://samjlevy.com/2012/04/upgrade-to-ubuntu-12-04-ruby-on-rails-gem-mysql2-error-libmysqlclient_r-so-16/#comments</comments>
		<pubDate>Sat, 28 Apr 2012 06:23:29 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[Error]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1536</guid>
		<description><![CDATA[When upgrading from Ubuntu 11.10 to 12.04, you may experience the following error with the Ruby on Rails gem mysql2: .rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': libmysqlclient_r.so.16: cannot open shared object file: No such file or directory This is because Ubuntu 12.04 is now &#8230; <a href="http://samjlevy.com/2012/04/upgrade-to-ubuntu-12-04-ruby-on-rails-gem-mysql2-error-libmysqlclient_r-so-16/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When upgrading from Ubuntu 11.10 to 12.04, you may experience the following error with the Ruby on Rails gem mysql2:</p>
<p><code>.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': libmysqlclient_r.so.16: cannot open shared object file: No such file or directory</code></p>
<p>This is because Ubuntu 12.04 is now using the newer libmysqlclient 18.  Creating a symlink won&#8217;t fix the problem&#8211; the mysql2 gem needs to be re-installed (and therefore recompiled) to support the latest version.</p>
<p></p><pre class="crayon-plain-tag">gem uninstall mysql2
# (all versions)
gem install mysql2</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2012/04/upgrade-to-ubuntu-12-04-ruby-on-rails-gem-mysql2-error-libmysqlclient_r-so-16/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Shell script for cloning a WordPress installation</title>
		<link>http://samjlevy.com/2011/12/shell-script-for-cloning-a-wordpress-installation/</link>
		<comments>http://samjlevy.com/2011/12/shell-script-for-cloning-a-wordpress-installation/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 23:30:27 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1521</guid>
		<description><![CDATA[The shell script below will copy a WordPress installation from one server to another- including the database. The script uses the &#8216;sed&#8217; command to update the new wp-config.php with the new server information, as well as replace all references to &#8230; <a href="http://samjlevy.com/2011/12/shell-script-for-cloning-a-wordpress-installation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The shell script below will copy a WordPress installation from one server to another- including the database. The script uses the &#8216;sed&#8217; command to update the new wp-config.php with the new server information, as well as replace all references to the original domain (such as in post_content) in the new DB with references to the new domain.  I wrote the script in order to create a &#8216;one-click&#8217; solution to mirroring a WP installation.  It will work with both single and multisite installations.</p>
<p><span style="color: #ff0000;"><strong>WARNING:</strong></span> Use at your own risk.  I recommend that you manually back up the original WP installation until you are confident that the script is configured correctly.  It is possible to inadvertently alter or erase your original installation if you do not configure the script&#8217;s variables correctly.  The script was written in the Mac OS environment and may require some alterations to work in your environment.</p>
<p></p><pre class="crayon-plain-tag">#!/bin/sh
echo &quot;WP Clone Start&quot;
START=$(date +%s)

SH_PATH=&quot;/Users/johndoe/Desktop/&quot; # Path to this shell script
MYSQL_PATH=&quot;/usr/local/mysql-5.1.60-osx10.6-x86_64/bin&quot; # Path to mysql and mysqldump

OLD_PATH=&quot;/Volumes/live&quot; # Path to original WP
OLD_DOMAIN=&quot;live.myserver.com&quot; # Domain for original WP
OLD_HOST=&quot;db.myserver.com&quot; # Database host for original WP
OLD_USER=&quot;liveuser&quot; # Database user for original WP
OLD_PASS=&quot;livepassword&quot; # Database password for original WP
OLD_DB=&quot;wp_live&quot; # Database name for original WP

NEW_PATH=&quot;/Volumes/dev&quot; # Path to new WP, folder must already exist
NEW_DOMAIN=&quot;dev.myserver.com&quot; # Domain for new WP
NEW_HOST=&quot;db.myserver.com&quot; # Database host for new WP
NEW_USER=&quot;devuser&quot; # Database user for new WP
NEW_PASS=&quot;devpassword&quot; # Database password for new WP
NEW_DB=&quot;wp_dev&quot; # Database name for new WP, database must already exist

datetime() { echo `date &quot;+%Y-%m-%d %H:%M:%S&quot;` ;}

echo $(datetime) &quot;Dumping $OLD_DB&quot;

cd &quot;$MYSQL_PATH&quot;
./mysqldump $OLD_DB -h$OLD_HOST -u$OLD_USER -p$OLD_PASS &gt; &quot;$SH_PATH/$OLD_DB.sql&quot;

echo $(datetime) &quot;Editing $OLD_DB.sql &gt; $NEW_DB.sql&quot;

cd &quot;$SH_PATH&quot;
sed 's/'$OLD_DOMAIN'/'$NEW_DOMAIN'/g' $OLD_DB.sql &gt; $NEW_DB.sql

echo $(datetime) &quot;Importing $NEW_DB.sql to $NEW_DB&quot;

cd &quot;$MYSQL_PATH&quot;
./mysql $NEW_DB -h$NEW_HOST -u$NEW_USER -p$NEW_PASS &lt; &quot;$SH_PATH/$NEW_DB.sql&quot;

echo $(datetime) &quot;Removing $OLD_DB.sql and $NEW_DB.sql&quot;

cd &quot;$SH_PATH&quot;
rm $OLD_DB.sql
rm $NEW_DB.sql

echo $(datetime) &quot;Removing $NEW_PATH contents&quot;

rm -rf &quot;$NEW_PATH/&quot;*

echo $(datetime) &quot;Copying files from $OLD_PATH to $NEW_PATH&quot;

cp -r &quot;$OLD_PATH/&quot;* &quot;$NEW_PATH&quot;

echo $(datetime) &quot;Editing wp-config.php&quot;

cd &quot;$NEW_PATH&quot;
sed 's/'$OLD_DOMAIN'/'$NEW_DOMAIN'/g' wp-config.php &gt; wp-config-temp.php
rm wp-config.php
mv wp-config-temp.php wp-config.php
sed 's/'$OLD_USER'/'$NEW_USER'/g' wp-config.php &gt; wp-config-temp.php
rm wp-config.php
mv wp-config-temp.php wp-config.php
sed 's/'$OLD_DB'/'$NEW_DB'/g' wp-config.php &gt; wp-config-temp.php
rm wp-config.php
mv wp-config-temp.php wp-config.php
sed 's/'$OLD_PASS'/'$NEW_PASS'/g' wp-config.php &gt; wp-config-temp.php
rm wp-config.php
mv wp-config-temp.php wp-config.php

DIFF=$(( $(date +%s) - $START ))
echo $(datetime) &quot;WP Clone Complete in $DIFF seconds&quot;</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/12/shell-script-for-cloning-a-wordpress-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multisite Dashboard Switcher Updated to 1.4</title>
		<link>http://samjlevy.com/2011/12/multisite-dashboard-switcher-updated-to-1-4/</link>
		<comments>http://samjlevy.com/2011/12/multisite-dashboard-switcher-updated-to-1-4/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 23:30:46 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[MSDS]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1517</guid>
		<description><![CDATA[Multisite Dashboard Switcher has been updated to version 1.4 Version 1.4 Changelog: Fixed issue with detection of Network Admin URL Improved localization support]]></description>
			<content:encoded><![CDATA[<p><a href="http://samjlevy.com/msds">Multisite Dashboard Switcher</a> has been updated to version 1.4</p>
<p>Version 1.4 Changelog:</p>
<ul>
<li>Fixed issue with detection of Network Admin URL</li>
<li>Improved localization support</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/12/multisite-dashboard-switcher-updated-to-1-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multisite Dashboard Switcher Updated to 1.3</title>
		<link>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-3/</link>
		<comments>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-3/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 23:30:31 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[MSDS]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1511</guid>
		<description><![CDATA[Multisite Dashboard Switcher has been updated to version 1.3 Version 1.3 Changelog: Added option to show site ID&#8217;s in menu]]></description>
			<content:encoded><![CDATA[<p><a href="http://samjlevy.com/msds">Multisite Dashboard Switcher</a> has been updated to version 1.3</p>
<p>Version 1.3 Changelog:</p>
<ul>
<li>Added option to show site ID&#8217;s in menu</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multisite Dashboard Switcher Updated to 1.2</title>
		<link>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-2/</link>
		<comments>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-2/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 23:30:36 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[MSDS]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1504</guid>
		<description><![CDATA[Multisite Dashboard Switcher has been updated to version 1.2 Version 1.2 Changelog: Added support for MU installations that have a hybrid of both subdomain and subdir URLs]]></description>
			<content:encoded><![CDATA[<p><a href="http://samjlevy.com/msds">Multisite Dashboard Switcher</a> has been updated to version 1.2</p>
<p>Version 1.2 Changelog:</p>
<ul>
<li>Added support for MU installations that have a hybrid of both subdomain and subdir URLs</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multisite Dashboard Switcher Updated to 1.1</title>
		<link>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-1/</link>
		<comments>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-1/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 19:14:34 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[MSDS]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1495</guid>
		<description><![CDATA[Multisite Dashboard Switcher has been updated to version 1.1 Version 1.1 Changelog: An issue with subdomain multisites has been addressed HTTPS persistence in links added &#8216;Visit&#8217; link added for each site in the dropdown]]></description>
			<content:encoded><![CDATA[<p><a href="http://samjlevy.com/msds">Multisite Dashboard Switcher</a> has been updated to version 1.1</p>
<p>Version 1.1 Changelog:</p>
<ul>
<li>An issue with subdomain multisites has been addressed</li>
<li>HTTPS persistence in links added</li>
<li>&#8216;Visit&#8217; link added for each site in the dropdown</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/11/multisite-dashboard-switcher-updated-to-1-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multisite Dashboard Switcher for WordPress Released</title>
		<link>http://samjlevy.com/2011/11/multisite-dashboard-switcher-for-wordpress-released/</link>
		<comments>http://samjlevy.com/2011/11/multisite-dashboard-switcher-for-wordpress-released/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 00:34:17 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[MSDS]]></category>
		<category><![CDATA[Multisite Dashboard Switcher]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1490</guid>
		<description><![CDATA[The Multisite Dashboard Switcher is a plugin written for WordPress that allows multisite administrators to easily switch between Dashboards. MSDS provides convenient access to options pages across every site in the network, reducing the number of clicks necessary to manage &#8230; <a href="http://samjlevy.com/2011/11/multisite-dashboard-switcher-for-wordpress-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://samjlevy.com/wp-content/uploads/2011/11/msds_screenshot.png" rel="none" target="_blank" rel="lightbox[1490]"><img class="aligncenter size-large wp-image-1478" title="MSDS" src="http://samjlevy.com/wp-content/uploads/2011/11/msds_screenshot-1024x568.png" alt="" width="584" height="323" /></a></p>
<p>The Multisite Dashboard Switcher is a plugin written for WordPress that allows multisite administrators to easily switch between Dashboards. MSDS provides convenient access to options pages across every site in the network, reducing the number of clicks necessary to manage settings. For larger networks, sites can be grouped by letter.</p>
<p><center><a href="http://wordpress.org/extend/plugins/multisite-dashboard-switcher/" target="_blank">View the plugin on WordPress.org</a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/11/multisite-dashboard-switcher-for-wordpress-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Use PHP and LDAP to list members of an Active Directory group (Improved)</title>
		<link>http://samjlevy.com/2011/10/use-php-and-ldap-to-list-members-of-an-active-directory-group-improved/</link>
		<comments>http://samjlevy.com/2011/10/use-php-and-ldap-to-list-members-of-an-active-directory-group-improved/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 01:28:19 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1460</guid>
		<description><![CDATA[PHP function that gets the members of an Active Directory group, and returns the Users&#8217; attributes as an array. This is an improved version of the snippet posted on 2/10/2011 The Function [crayon-4fb6dd3b8a6b1/] Example Output [crayon-4fb6dd3b8a6ef/]]]></description>
			<content:encoded><![CDATA[<p>PHP function that gets the members of an Active Directory group, and returns the Users&#8217; attributes as an array.</p>
<p>This is an improved version of <a href="http://samjlevy.com/2011/02/using-php-and-ldap-to-list-of-members-of-an-active-directory-group/">the snippet posted on 2/10/2011</a></p>
<h2>The Function</h2>
<p></p><pre class="crayon-plain-tag">&lt;?php
function get_members($group=FALSE,$inclusive=FALSE) {
    // Active Directory server
    $ldap_host = &quot;ad.domain&quot;;
 
    // Active Directory DN
    $ldap_dn = &quot;CN=Users,DC=ad,DC=domain&quot;;
 
    // Domain, for purposes of constructing $user
    $ldap_usr_dom = &quot;@&quot;.$ldap_host;
 
    // Active Directory user
    $user = &quot;jdoe&quot;;
    $password = &quot;password1234!&quot;;
 
    // User attributes we want to keep
    // List of User Object properties:
    // http://www.dotnetactivedirectory.com/Understanding_LDAP_Active_Directory_User_Object_Properties.html
    $keep = array(
        &quot;samaccountname&quot;,
        &quot;distinguishedname&quot;
    );
 
    // Connect to AD
    $ldap = ldap_connect($ldap_host) or die(&quot;Could not connect to LDAP&quot;);
    ldap_bind($ldap,$user.$ldap_usr_dom,$password) or die(&quot;Could not bind to LDAP&quot;);
 
 	// Begin building query
 	if($group) $query = &quot;(&amp;&quot;; else $query = &quot;&quot;;

 	$query .= &quot;(&amp;(objectClass=user)(objectCategory=person))&quot;;

    // Filter by memberOf, if group is set
    if(is_array($group)) {
    	// Looking for a members amongst multiple groups
    		if($inclusive) {
    			// Inclusive - get users that are in any of the groups
    			// Add OR operator
    			$query .= &quot;(|&quot;;
    		} else {
				// Exclusive - only get users that are in all of the groups
				// Add AND operator
				$query .= &quot;(&amp;&quot;;
    		}

    		// Append each group
    		foreach($group as $g) $query .= &quot;(memberOf=CN=$g,$ldap_dn)&quot;;

    		$query .= &quot;)&quot;;
    } elseif($group) {
    	// Just looking for membership of one group
    	$query .= &quot;(memberOf=CN=$group,$ldap_dn)&quot;;
    }

    // Close query
    if($group) $query .= &quot;)&quot;; else $query .= &quot;&quot;;

	// Uncomment to output queries onto page for debugging
	// print_r($query);

    // Search AD
    $results = ldap_search($ldap,$ldap_dn,$query);
    $entries = ldap_get_entries($ldap, $results);
 
    // Remove first entry (it's always blank)
    array_shift($entries);
 
    $output = array(); // Declare the output array
 
    $i = 0; // Counter
    // Build output array
    foreach($entries as $u) {
        foreach($keep as $x) {
        	// Check for attribute
    		if(isset($u[$x][0])) $attrval = $u[$x][0]; else $attrval = NULL;

        	// Append attribute to output array
        	$output[$i][$x] = $attrval;
        }
        $i++;
    }
 
    return $output;
}

// Example Output

print_r(get_members()); // Gets all users in OU 'Users'

print_r(get_members(&quot;Test Group&quot;)); // Gets all members of 'Test Group'

print_r(get_members(
			array(&quot;Test Group&quot;,&quot;Test Group 2&quot;)
		)); // EXCLUSIVE: Gets only members that belong to BOTH 'Test Group' AND 'Test Group 2'

print_r(get_members(
			array(&quot;Test Group&quot;,&quot;Test Group 2&quot;),TRUE
		)); // INCLUSIVE: Gets members that belong to EITHER 'Test Group' OR 'Test Group 2'
?&gt;</pre><p></p>
<h2>Example Output</h2>
<p></p><pre class="crayon-plain-tag">Array
(
    [0] =&gt; Array
        (
            [samaccountname] =&gt; sam
            [distinguishedname] =&gt; CN=sam,CN=Users,DC=ad,DC=domain
        )

    [1] =&gt; Array
        (
            [samaccountname] =&gt; jdoe
            [distinguishedname] =&gt; CN=John Doe,CN=Users,DC=ad,DC=domain
        )

)</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/10/use-php-and-ldap-to-list-members-of-an-active-directory-group-improved/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

