<?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, 04 Jan 2012 19:19:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 420px;"><table class="bash"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="de1"><pre class="de1"><span class="co0">#!/bin/sh</span>
<span class="kw3">echo</span> <span class="st0">&quot;WP Clone Start&quot;</span>
<span class="re2">START</span>=$<span class="br0">&#40;</span><span class="kw2">date</span> +<span class="sy0">%</span>s<span class="br0">&#41;</span>
&nbsp;
<span class="re2">SH_PATH</span>=<span class="st0">&quot;/Users/johndoe/Desktop/&quot;</span> <span class="co0"># Path to this shell script</span>
<span class="re2">MYSQL_PATH</span>=<span class="st0">&quot;/usr/local/mysql-5.1.60-osx10.6-x86_64/bin&quot;</span> <span class="co0"># Path to mysql and mysqldump</span>
&nbsp;
<span class="re2">OLD_PATH</span>=<span class="st0">&quot;/Volumes/live&quot;</span> <span class="co0"># Path to original WP</span>
<span class="re2">OLD_DOMAIN</span>=<span class="st0">&quot;live.myserver.com&quot;</span> <span class="co0"># Domain for original WP</span>
<span class="re2">OLD_HOST</span>=<span class="st0">&quot;db.myserver.com&quot;</span> <span class="co0"># Database host for original WP</span>
<span class="re2">OLD_USER</span>=<span class="st0">&quot;liveuser&quot;</span> <span class="co0"># Database user for original WP</span>
<span class="re2">OLD_PASS</span>=<span class="st0">&quot;livepassword&quot;</span> <span class="co0"># Database password for original WP</span>
<span class="re2">OLD_DB</span>=<span class="st0">&quot;wp_live&quot;</span> <span class="co0"># Database name for original WP</span>
&nbsp;
<span class="re2">NEW_PATH</span>=<span class="st0">&quot;/Volumes/dev&quot;</span> <span class="co0"># Path to new WP, folder must already exist</span>
<span class="re2">NEW_DOMAIN</span>=<span class="st0">&quot;dev.myserver.com&quot;</span> <span class="co0"># Domain for new WP</span>
<span class="re2">NEW_HOST</span>=<span class="st0">&quot;db.myserver.com&quot;</span> <span class="co0"># Database host for new WP</span>
<span class="re2">NEW_USER</span>=<span class="st0">&quot;devuser&quot;</span> <span class="co0"># Database user for new WP</span>
<span class="re2">NEW_PASS</span>=<span class="st0">&quot;devpassword&quot;</span> <span class="co0"># Database password for new WP</span>
<span class="re2">NEW_DB</span>=<span class="st0">&quot;wp_dev&quot;</span> <span class="co0"># Database name for new WP, database must already exist</span>
&nbsp;
datetime<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">echo</span> <span class="sy0">`</span><span class="kw2">date</span> <span class="st0">&quot;+%Y-%m-%d %H:%M:%S&quot;</span><span class="sy0">`</span> ;<span class="br0">&#125;</span>
&nbsp;
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;Dumping <span class="es2">$OLD_DB</span>&quot;</span>
&nbsp;
<span class="kw3">cd</span> <span class="st0">&quot;<span class="es2">$MYSQL_PATH</span>&quot;</span>
.<span class="sy0">/</span>mysqldump <span class="re1">$OLD_DB</span> -h<span class="re1">$OLD_HOST</span> -u<span class="re1">$OLD_USER</span> -p<span class="re1">$OLD_PASS</span> <span class="sy0">&gt;</span> <span class="st0">&quot;<span class="es2">$SH_PATH</span>/<span class="es2">$OLD_DB</span>.sql&quot;</span>
&nbsp;
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;Editing <span class="es2">$OLD_DB</span>.sql &gt; <span class="es2">$NEW_DB</span>.sql&quot;</span>
&nbsp;
<span class="kw3">cd</span> <span class="st0">&quot;<span class="es2">$SH_PATH</span>&quot;</span>
<span class="kw2">sed</span> <span class="st_h">'s/'</span><span class="re1">$OLD_DOMAIN</span><span class="st_h">'/'</span><span class="re1">$NEW_DOMAIN</span><span class="st_h">'/g'</span> <span class="re1">$OLD_DB</span>.sql <span class="sy0">&gt;</span> <span class="re1">$NEW_DB</span>.sql
&nbsp;
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;Importing <span class="es2">$NEW_DB</span>.sql to <span class="es2">$NEW_DB</span>&quot;</span>
&nbsp;
<span class="kw3">cd</span> <span class="st0">&quot;<span class="es2">$MYSQL_PATH</span>&quot;</span>
.<span class="sy0">/</span>mysql <span class="re1">$NEW_DB</span> -h<span class="re1">$NEW_HOST</span> -u<span class="re1">$NEW_USER</span> -p<span class="re1">$NEW_PASS</span> <span class="sy0">&lt;</span> <span class="st0">&quot;<span class="es2">$SH_PATH</span>/<span class="es2">$NEW_DB</span>.sql&quot;</span>
&nbsp;
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;Removing <span class="es2">$OLD_DB</span>.sql and <span class="es2">$NEW_DB</span>.sql&quot;</span>
&nbsp;
<span class="kw3">cd</span> <span class="st0">&quot;<span class="es2">$SH_PATH</span>&quot;</span>
<span class="kw2">rm</span> <span class="re1">$OLD_DB</span>.sql
<span class="kw2">rm</span> <span class="re1">$NEW_DB</span>.sql
&nbsp;
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;Removing <span class="es2">$NEW_PATH</span> contents&quot;</span>
&nbsp;
<span class="kw2">rm</span> <span class="re5">-rf</span> <span class="st0">&quot;<span class="es2">$NEW_PATH</span>/&quot;</span><span class="sy0">*</span>
&nbsp;
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;Copying files from <span class="es2">$OLD_PATH</span> to <span class="es2">$NEW_PATH</span>&quot;</span>
&nbsp;
<span class="kw2">cp</span> <span class="re5">-r</span> <span class="st0">&quot;<span class="es2">$OLD_PATH</span>/&quot;</span><span class="sy0">*</span> <span class="st0">&quot;<span class="es2">$NEW_PATH</span>&quot;</span>
&nbsp;
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;Editing wp-config.php&quot;</span>
&nbsp;
<span class="kw3">cd</span> <span class="st0">&quot;<span class="es2">$NEW_PATH</span>&quot;</span>
<span class="kw2">sed</span> <span class="st_h">'s/'</span><span class="re1">$OLD_DOMAIN</span><span class="st_h">'/'</span><span class="re1">$NEW_DOMAIN</span><span class="st_h">'/g'</span> wp-config.php <span class="sy0">&gt;</span> wp-config-temp.php
<span class="kw2">rm</span> wp-config.php
<span class="kw2">mv</span> wp-config-temp.php wp-config.php
<span class="kw2">sed</span> <span class="st_h">'s/'</span><span class="re1">$OLD_USER</span><span class="st_h">'/'</span><span class="re1">$NEW_USER</span><span class="st_h">'/g'</span> wp-config.php <span class="sy0">&gt;</span> wp-config-temp.php
<span class="kw2">rm</span> wp-config.php
<span class="kw2">mv</span> wp-config-temp.php wp-config.php
<span class="kw2">sed</span> <span class="st_h">'s/'</span><span class="re1">$OLD_DB</span><span class="st_h">'/'</span><span class="re1">$NEW_DB</span><span class="st_h">'/g'</span> wp-config.php <span class="sy0">&gt;</span> wp-config-temp.php
<span class="kw2">rm</span> wp-config.php
<span class="kw2">mv</span> wp-config-temp.php wp-config.php
<span class="kw2">sed</span> <span class="st_h">'s/'</span><span class="re1">$OLD_PASS</span><span class="st_h">'/'</span><span class="re1">$NEW_PASS</span><span class="st_h">'/g'</span> wp-config.php <span class="sy0">&gt;</span> wp-config-temp.php
<span class="kw2">rm</span> wp-config.php
<span class="kw2">mv</span> wp-config-temp.php wp-config.php
&nbsp;
<span class="re2">DIFF</span>=$<span class="br0">&#40;</span><span class="br0">&#40;</span> $<span class="br0">&#40;</span><span class="kw2">date</span> +<span class="sy0">%</span>s<span class="br0">&#41;</span> - <span class="re1">$START</span> <span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="kw3">echo</span> $<span class="br0">&#40;</span>datetime<span class="br0">&#41;</span> <span class="st0">&quot;WP Clone Complete in <span class="es2">$DIFF</span> seconds&quot;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div><div class="bwp-syntax-source"><pre class="no-parse">#!/bin/sh
echo "WP Clone Start"
START=$(date +%s)

SH_PATH="/Users/johndoe/Desktop/" # Path to this shell script
MYSQL_PATH="/usr/local/mysql-5.1.60-osx10.6-x86_64/bin" # Path to mysql and mysqldump

OLD_PATH="/Volumes/live" # Path to original WP
OLD_DOMAIN="live.myserver.com" # Domain for original WP
OLD_HOST="db.myserver.com" # Database host for original WP
OLD_USER="liveuser" # Database user for original WP
OLD_PASS="livepassword" # Database password for original WP
OLD_DB="wp_live" # Database name for original WP

NEW_PATH="/Volumes/dev" # Path to new WP, folder must already exist
NEW_DOMAIN="dev.myserver.com" # Domain for new WP
NEW_HOST="db.myserver.com" # Database host for new WP
NEW_USER="devuser" # Database user for new WP
NEW_PASS="devpassword" # Database password for new WP
NEW_DB="wp_dev" # Database name for new WP, database must already exist

datetime() { echo `date "+%Y-%m-%d %H:%M:%S"` ;}

echo $(datetime) "Dumping $OLD_DB"

cd "$MYSQL_PATH"
./mysqldump $OLD_DB -h$OLD_HOST -u$OLD_USER -p$OLD_PASS &gt; "$SH_PATH/$OLD_DB.sql"

echo $(datetime) "Editing $OLD_DB.sql &gt; $NEW_DB.sql"

cd "$SH_PATH"
sed 's/'$OLD_DOMAIN'/'$NEW_DOMAIN'/g' $OLD_DB.sql &gt; $NEW_DB.sql

echo $(datetime) "Importing $NEW_DB.sql to $NEW_DB"

cd "$MYSQL_PATH"
./mysql $NEW_DB -h$NEW_HOST -u$NEW_USER -p$NEW_PASS &lt; "$SH_PATH/$NEW_DB.sql"

echo $(datetime) "Removing $OLD_DB.sql and $NEW_DB.sql"

cd "$SH_PATH"
rm $OLD_DB.sql
rm $NEW_DB.sql

echo $(datetime) "Removing $NEW_PATH contents"

rm -rf "$NEW_PATH/"*

echo $(datetime) "Copying files from $OLD_PATH to $NEW_PATH"

cp -r "$OLD_PATH/"* "$NEW_PATH"

echo $(datetime) "Editing wp-config.php"

cd "$NEW_PATH"
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) "WP Clone Complete in $DIFF seconds"</pre></div></div>

]]></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 1 2 3 4 5 6 7 8 &#8230; <a href="http://samjlevy.com/2011/10/use-php-and-ldap-to-list-members-of-an-active-directory-group-improved/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 420px;"><table class="php"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="de1"><pre class="de1"><span class="kw2">&lt;?php</span>
<span class="kw2">function</span> get_members<span class="br0">&#40;</span><span class="re0">$group</span><span class="sy0">=</span><span class="kw4">FALSE</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="co1">// Active Directory server</span>
&nbsp; &nbsp; <span class="re0">$ldap_host</span> <span class="sy0">=</span> <span class="st0">&quot;ad.domain&quot;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="co1">// Active Directory DN</span>
&nbsp; &nbsp; <span class="re0">$ldap_dn</span> <span class="sy0">=</span> <span class="st0">&quot;CN=Users,DC=ad,DC=domain&quot;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="co1">// domain, for purposes of constructing $user</span>
&nbsp; &nbsp; <span class="re0">$ldap_usr_dom</span> <span class="sy0">=</span> <span class="st0">&quot;@&quot;</span><span class="sy0">.</span><span class="re0">$ldap_host</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="co1">// Active Directory user</span>
&nbsp; &nbsp; <span class="re0">$user</span> <span class="sy0">=</span> <span class="st0">&quot;jdoe&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="re0">$password</span> <span class="sy0">=</span> <span class="st0">&quot;password&quot;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="co1">// User attributes we want to keep</span>
&nbsp; &nbsp; <span class="co1">// List of User Object properties: http://www.dotnetactivedirectory.com/Understanding_LDAP_Active_Directory_User_Object_Properties.html</span>
&nbsp; &nbsp; <span class="re0">$keep</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;samaccountname&quot;</span><span class="sy0">,</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;distinguishedname&quot;</span>
&nbsp; &nbsp; <span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="co1">// Connect and search AD</span>
&nbsp; &nbsp; <span class="re0">$ldap</span> <span class="sy0">=</span> <span class="kw3">ldap_connect</span><span class="br0">&#40;</span><span class="re0">$ldap_host</span><span class="br0">&#41;</span> or <span class="kw3">die</span><span class="br0">&#40;</span><span class="st0">&quot;Could not connect to LDAP&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="kw3">ldap_bind</span><span class="br0">&#40;</span><span class="re0">$ldap</span><span class="sy0">,</span><span class="re0">$user</span><span class="sy0">.</span><span class="re0">$ldap_usr_dom</span><span class="sy0">,</span><span class="re0">$password</span><span class="br0">&#41;</span> or <span class="kw3">die</span><span class="br0">&#40;</span><span class="st0">&quot;Could not bind to LDAP&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="co1">// filter by memberOf, if group is set</span>
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$group</span><span class="br0">&#41;</span> <span class="re0">$addtl</span> <span class="sy0">=</span> <span class="st0">&quot;(memberOf=CN=<span class="es4">$group</span>,<span class="es4">$ldap_dn</span>)&quot;</span><span class="sy0">;</span> <span class="kw1">else</span> <span class="re0">$addtl</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="re0">$results</span> <span class="sy0">=</span> <span class="kw3">ldap_search</span><span class="br0">&#40;</span><span class="re0">$ldap</span><span class="sy0">,</span><span class="re0">$ldap_dn</span><span class="sy0">,</span><span class="st0">&quot;(&amp;(objectClass=User)<span class="es4">$addtl</span>)&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="re0">$entries</span> <span class="sy0">=</span> <span class="kw3">ldap_get_entries</span><span class="br0">&#40;</span><span class="re0">$ldap</span><span class="sy0">,</span> <span class="re0">$results</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="co1">// Remove first entry (it's always blank)</span>
&nbsp; &nbsp; <span class="kw3">array_shift</span><span class="br0">&#40;</span><span class="re0">$entries</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="re0">$output</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// Declare the output array</span>
&nbsp;
&nbsp; &nbsp; <span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="co1">// Counter</span>
&nbsp; &nbsp; <span class="co1">// Build output array</span>
&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$entries</span> <span class="kw1">as</span> <span class="re0">$u</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$keep</span> <span class="kw1">as</span> <span class="re0">$x</span><span class="br0">&#41;</span> <span class="re0">$output</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="re0">$x</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$u</span><span class="br0">&#91;</span><span class="re0">$x</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$i</span><span class="sy0">++;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$output</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw3">print_r</span><span class="br0">&#40;</span>get_members<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// Gets all users in 'Users'</span>
<span class="kw3">print_r</span><span class="br0">&#40;</span>get_members<span class="br0">&#40;</span><span class="st0">&quot;Test Group&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// Gets all members of 'Test Group'</span>
<span class="sy1">?&gt;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div><div class="bwp-syntax-source"><pre class="no-parse">&lt;?php
function get_members($group=FALSE) {
	// Active Directory server
	$ldap_host = "ad.domain";

	// Active Directory DN
	$ldap_dn = "CN=Users,DC=ad,DC=domain";

	// domain, for purposes of constructing $user
	$ldap_usr_dom = "@".$ldap_host;

	// Active Directory user
	$user = "jdoe";
	$password = "password";

	// 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(
	    "samaccountname",
	    "distinguishedname"
	);

	// Connect and search AD
	$ldap = ldap_connect($ldap_host) or die("Could not connect to LDAP");
	ldap_bind($ldap,$user.$ldap_usr_dom,$password) or die("Could not bind to LDAP");

	// filter by memberOf, if group is set
	if($group) $addtl = "(memberOf=CN=$group,$ldap_dn)"; else $addtl = "";

	$results = ldap_search($ldap,$ldap_dn,"(&amp;(objectClass=User)$addtl)");
	$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) $output[$i][$x] = $u[$x][0];
		$i++;
	}

	return $output;
}

print_r(get_members()); // Gets all users in 'Users'
print_r(get_members("Test Group")); // Gets all members of 'Test Group'
?&gt;</pre></div></div>

<h2>Example Output</h2>
<pre>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>
]]></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>1</slash:comments>
		</item>
		<item>
		<title>MySQL Levenshtein, Win 64bit versions compiled</title>
		<link>http://samjlevy.com/2011/08/mysql-levenshtein-win-64bit-versions-compiled/</link>
		<comments>http://samjlevy.com/2011/08/mysql-levenshtein-win-64bit-versions-compiled/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 03:52:53 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL Damerau-Levenshtein UDF]]></category>
		<category><![CDATA[MySQL Levenshtein UDF]]></category>
		<category><![CDATA[MySQL UDF]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1436</guid>
		<description><![CDATA[Due to popular request, I have compiled Win64 versions of Joshua Drew&#8216;s and Sean Collins&#8216; Levenshtein UDF&#8217;s.  The zip files in the original post have been updated, as well as the PDF compilation instructions. Special thanks to Michael Tobias for &#8230; <a href="http://samjlevy.com/2011/08/mysql-levenshtein-win-64bit-versions-compiled/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Due to popular request, I have compiled Win64 versions of <a href="http://joshdrew.com/" target="_blank">Joshua Drew</a>&#8216;s and <a href="http://blog.lolyco.com/sean/" target="_blank">Sean Collins</a>&#8216; Levenshtein UDF&#8217;s.  The zip files <a href="http://samjlevy.com/2011/03/mysql-levenshtein-and-damerau-levenshtein-udfs/">in the original post</a> have been updated, as well as the PDF compilation instructions.</p>
<p>Special thanks to Michael Tobias for testing.</p>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/08/mysql-levenshtein-win-64bit-versions-compiled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solution for WordPress and WinCache, &#8216;Plugin update failed&#8217;</title>
		<link>http://samjlevy.com/2011/08/solution-for-wordpress-and-wincache-plugin-update-failed/</link>
		<comments>http://samjlevy.com/2011/08/solution-for-wordpress-and-wincache-plugin-update-failed/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 23:32:01 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[IIS 7]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WinCache]]></category>
		<category><![CDATA[Windows Server 2008]]></category>

		<guid isPermaLink="false">http://samjlevy.com/?p=1342</guid>
		<description><![CDATA[There is a bug with the current release (1.1.0) of WinCache that causes WordPress plugins to fail during update. When trying to delete the plugin after a failed update, a permissions error message is received. The solution to this problem &#8230; <a href="http://samjlevy.com/2011/08/solution-for-wordpress-and-wincache-plugin-update-failed/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There is a bug with the current release (1.1.0) of WinCache that causes WordPress plugins to fail during update.</p>
<p><a href="http://samjlevy.com/wp-content/uploads/2011/08/wordpress_update_fail.jpg" rel="lightbox[1342]"><img class="aligncenter size-full wp-image-1428" title="WordPress Update Plugin Fail" src="http://samjlevy.com/wp-content/uploads/2011/08/wordpress_update_fail.jpg" alt="" /></a></p>
<p>When trying to delete the plugin after a failed update, a permissions error message is received.</p>
<p><a href="http://samjlevy.com/wp-content/uploads/2011/08/wordpress_plugin_locked.png" rel="lightbox[1342]"><img class="alignleft size-large wp-image-1348" title="WordPress folder permission denied" src="http://samjlevy.com/wp-content/uploads/2011/08/wordpress_plugin_locked-1024x609.png" alt="" /></a></p>
<p><span id="more-1342"></span></p>
<p>The solution to this problem is to replace your php_wincache.dll in C:\Program Files\PHP\ext\ with the latest development version of the extension, and then restart IIS.</p>
<p>The latest development version of WinCache can be downloaded <a href="http://sourceforge.net/projects/wincache/files/development/" target="_blank">here</a>.</p>
<p>If you are still having problems, verify that IUSR or your Application Pool user has Modify permissions on the wp-content directory.</p>
<p><a href="http://samjlevy.com/wp-content/uploads/2011/08/iusr.png" rel="lightbox[1342]"><img class="aligncenter size-full wp-image-1429" title="IUSR Modify Permission" src="http://samjlevy.com/wp-content/uploads/2011/08/iusr.png" alt="" /></a></p>
<p><strong>More on this issue:</strong><br />
<a href="http://www.whitworth.org/2009/03/10/plugin-upgrade-failed-in-wordpress-using-iis-7/" target="_blank">Plugin upgrade Failed in WordPress Using IIS 7 | Rickey Whitworth&#8217;s Blog</a><br />
<a href="http://ruslany.net/2011/04/wincache-and-wordpress-plugin-upgrade-problem/" target="_blank">WinCache and WordPress plugin upgrade problem | RuslanY</a></p>
]]></content:encoded>
			<wfw:commentRss>http://samjlevy.com/2011/08/solution-for-wordpress-and-wincache-plugin-update-failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

