<?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>Ardamis &#187; coding</title>
	<atom:link href="http://www.ardamis.com/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ardamis.com</link>
	<description>Ardamis is a blog about web development and technology in general.</description>
	<lastBuildDate>Thu, 02 Feb 2012 07:07:02 +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>A PHP MySQL snippet for looking up names</title>
		<link>http://www.ardamis.com/2011/10/16/a-php-mysql-snippet-for-looking-up-names/</link>
		<comments>http://www.ardamis.com/2011/10/16/a-php-mysql-snippet-for-looking-up-names/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 00:26:35 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1775</guid>
		<description><![CDATA[A PHP snippet and MySQL query for an Ajax autocompleter lookup of people names by either "Firstname Lastname" or "Lastname, Firstname" from a single input field.]]></description>
			<content:encoded><![CDATA[<p>For a recent project, I needed to create a form that would perform a look up of people names in a MySQL database, but I wanted to use a single input field.  To make it easy on the users of the form, I wanted the input field to accept names in either &#8220;Firstname Lastname&#8221; or &#8220;Lastname, Firstname&#8221; format, and I wanted it to autocomplete matches as the users typed, including when they typed both names separated by a space or a comma followed by a space.</p>
<p>The Ajax lookup was quick work with <a href="http://jqueryui.com/demos/autocomplete/">jQuery UI&#8217;s Autocomplete widget</a>.  The harder part was figuring out the most simple table structure and an appropriate SQL query.</p>
<h2>A flawed beginning</h2>
<p>My people table contains a &#8220;first_name&#8221; column and a &#8220;last_name&#8221; column, nothing uncommon there.  To get the project out the door, I wrote a PHP function that ran two ALTER TABLE queries on the people table to create two additional columns for pre-formatted strings (column &#8220;firstlast&#8221;, to be formatted as &#8220;Firstname Lastname&#8221;, and column &#8220;lastfirst&#8221;, to be formatted as &#8220;Lastname, Firstname&#8221;), added indexes on these columns, and then walked through each record in the table, populating these new fields.  I then wrote a very straight forward SQL query to perform a lookup on both fields.  The PHP and query looked something like this:</p>
<pre class="brush: php; title: ; notranslate">
// The jQuery UI Autocomplete widget passes the user input as a value for the parameter &quot;name&quot;
$name= $_GET['name'];

// This SQL query uses argument swapping
$query = sprintf(&quot;SELECT * FROM people WHERE (`firstlast` LIKE '%1\$s' OR `lastfirst` LIKE '%1\$s') ORDER BY `lastfirst` ASC&quot;,
mysql_real_escape_string($name. &quot;%&quot;, $link));
</pre>
<p>This was effective, accurate, and pretty fast, but the addition of columns bothered me and I didn&#8217;t like that I needed to run a process to generate those pre-formatted fields each time a record was added to the table (or if a change was made to an existing record).  One possible alternative was to watch the input and match either lastname or firstname until the user entered a comma or a space, then explode the string on the comma or space and search more precisely.  Once a comma or a space was encountered, I felt pretty sure that I would be able to accurately determine which part of the input was the first name and which was the last name.  But this had that same inefficient, clunky bad-code-smell as the extra columns.  (Explode is one of those functions that I try to avoid using.)  Writing lots of extra PHP didn&#8217;t seem necessary or right.</p>
<p>I&#8217;m much more comfortable with PHP than with MySQL queries, but I realize that one can do some amazing things within the SQL query, and that it&#8217;s probably faster to use SQL to perform some functions.  So, I decided that I&#8217;d try to work up a query that solved my problem, rather than write more lines of PHP.</p>
<h2>CONCAT_WS to the rescue</h2>
<p>I Googled around for a bit and settled on using <code><a href="http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_concat-ws">CONCAT_WS</a></code> to concatenate the first names and last names into a single string be matched, but found it a bit confusing to work with.  I kept trying to use it to create an alias, &#8220;lastfirst&#8221;, and then use the alias in the WHERE clause, which doesn&#8217;t work, or I was getting the literal column names back instead of the values.  Eventually, I hit upon the correct usage.</p>
<p>The PHP and query now looks like this:</p>
<pre class="brush: php; title: ; notranslate">
// The jQuery UI Autocomplete widget passes the user input as a value for the parameter &quot;name&quot;
$name= $_GET['name'];

// This SQL query uses argument swapping
$query = sprintf(&quot;SELECT *, CONCAT_WS(  ', ',  `last_name`,  `first_name` ) as lastfirst FROM people WHERE (CONCAT_WS(  ', ',  `last_name`,  `first_name` ) LIKE '%1\$s' OR CONCAT_WS(  ' ',  `first_name`,  `last_name` ) LIKE '%1\$s') ORDER BY lastfirst ASC&quot;,
mysql_real_escape_string($name. &quot;%&quot;, $link));
</pre>
<p>The first instance of CONCAT_WS isn&#8217;t needed for the lookup.  The first instance allows me to order the results alphabetically and provides me an array key of &#8220;lastfirst&#8221; with a value of the person&#8217;s name already formatted as &#8220;Lastname, Firstname&#8221;, so I don&#8217;t have to do it later with PHP.  The lookup comes from the two instances of CONCAT_WS in the WHERE clause.  I haven&#8217;t done any performance measuring here, but the results of the lookup get back to the user plenty fast enough, if not just as quickly as the method using dedicated columns.</p>
<p>The result of the query is output back to the page as JSON-formatted data for use in the jQuery Autocomplete.</p>
<p>The end result works exactly as I had hoped.  A user of the form is able to type a person&#8217;s name in whatever way is comfortable to them, as &#8220;Bob Smith&#8221; or &#8220;Smith, Bob&#8221;, and the matches are found either way.  The only thing it doesn&#8217;t do is output the matches back to the autocompleter in the same format that the user is using.  But I can live with that for now. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/10/16/a-php-mysql-snippet-for-looking-up-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dreamweaver open files in code view</title>
		<link>http://www.ardamis.com/2011/10/01/dreamweaver-open-files-in-code-view/</link>
		<comments>http://www.ardamis.com/2011/10/01/dreamweaver-open-files-in-code-view/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 04:47:00 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1745</guid>
		<description><![CDATA[A simple registry merge can fix Dreamweaver's default setting of opening .php and .asp files in Design view, instead of Code view.]]></description>
			<content:encoded><![CDATA[<p>If there is one thing that bothers me about Dreamweaver&#8217;s default settings (other than its annoying habit of <a href="http://www.ardamis.com/2009/09/30/dreamweaver-rewriting-valid-code-as-camelcase/">rewriting valid code as camelCase</a>), it is that double-clicking .php and .asp files launches Dreamweaver in Design view.  Who on earth thinks that people generally want to open these kinds of files in anything other than code view?</p>
<p>Well, thankfully, this ridiculous behavior can be changed with a quick registry tweak.  Just add an extension to the &#8220;Open As Text&#8221; value to cause Dreamweaver to always open that file type in code view.  The .reg file below assumes you&#8217;re running Dreamweaver CS5.</p>
<pre class="brush: plain; title: ; notranslate">
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Adobe\Dreamweaver CS5\Helper Applications Preferences]
&quot;Open As Text&quot;=&quot;.js .asa .css .cs .config .inc .txt .as .asc .asr .vb .htaccess .htpasswd .php .asp .html&quot;
</pre>
<p>It would be nice if Dreamweaver were smart enough to realize that, if your preferred layout is Coder, any file should be opened in Code view.</p>
<p>The link below explains how to do the same thing via Edit | Preferences.</p>
<p>Source: <a href="http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7be2a.html">Open files in Code view by default</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/10/01/dreamweaver-open-files-in-code-view/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A cache-friendly method for reducing WordPress comment spam</title>
		<link>http://www.ardamis.com/2011/08/27/a-cache-proof-method-for-reducing-comment-spam/</link>
		<comments>http://www.ardamis.com/2011/08/27/a-cache-proof-method-for-reducing-comment-spam/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 08:34:53 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[comment spam]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[web app]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1673</guid>
		<description><![CDATA[A safe-for-cached-pages method of filtering out spam comments by requiring at least some time to have passed between the time the page is loaded and the form is submitted.]]></description>
			<content:encoded><![CDATA[<p>In the endless battle against WordPress comment spam, I&#8217;ve developed and then refined a few different methods for preventing spam from getting to the database to begin with.  My philosophy has always been that a human visitor and a spam bot behave differently (after all, we&#8217;re not dealing with <a href="http://en.wikipedia.org/wiki/Do_Androids_Dream_of_Electric_Sheep%3F#Androids">Nexus-6 model androids</a> here), and an effective spam-prevention method should be able to recognize the differences.  I also have a dislike for CAPTCHA methods that require a human visitor to <em>prove</em>, via an intentionally difficult test, that they aren&#8217;t a bot.  The ideal method, I feel, would be invisible to a human visitor, but still accurately identify comments submitted by bots.</p>
<h2>A history of spam fighting</h2>
<p>The most successful and simple method I found was a server-side system for <a href="http://www.ardamis.com/2007/12/15/using-timestamps-to-reduce-wordpress-comment-spam/">reducing comment spam by using a handshake method involving timestamps</a> on hidden form fields.  The general idea was that a bot would submit a comment more quickly than a human visitor, so if the comment was submitted too soon after the page was loaded, it was rejected.  A human caught in this trap would be able to click the Back button on the browser to resubmit.  This had proven to be very effective on ardamis.com, cutting the number of <a href="http://www.ardamis.com/2010/08/09/reducing-wordpress-spam-comments/">spam comments intercepted by Akismet per day to nearly zero</a>.  For a long time, the only problem was that it required modifying a core WordPress file, <strong>wp-comments-post.php</strong>.  Each time WordPress was updated, the core file was replaced.  If I didn&#8217;t then go back and make my modifications again, <a href="http://www.ardamis.com/2011/01/18/a-chart-illustrating-the-reduction-in-comment-spam-at-ardamis-com/">I would lose the spam protection</a> until I made the changes.  As it became easier to update WordPress (via the admin panel) and I updated it more frequently, editing the core file became more of a nuisance.</p>
<h2>A huge facepalm</h2>
<p>When Google began weighting page load times as part of its ranking algorithm, I implemented the <a href="http://wordpress.org/extend/plugins/wp-super-cache/" title="WP Super Cache">WP Super Cache</a> caching plugin on ardamis.com and configured it to use .htaccess and mod_rewrite to serve cache files.  Page load times certainly decreased, but the amount of spam detected by Akismet increased.  After a while, I realized that this was because the spam bots were submitting comments from static, cached pages, and the timestamps on those pages, which had been generated server-side with PHP, were already minutes old when the page was requested.  The form processing script, which normally rejects comments that are submitted too quickly to be written by a human visitor, happily accepted the timestamps.  Even worse, a second function of my anti-spam method also rejected comments that were submitted 10 minutes or more after the page was loaded.  Of course, most of the visitors were being served cached pages that were already more than 10 minutes old, so even legitimate comments were being rejected.  Using PHP to generate my timestamps obviously was not going to work if I wanted to keep serving cached pages.</p>
<h2>JavaScript to the rescue</h2>
<p>Generating real-time timestamps on cached pages requires JavaScript.  But instead of a reliable server clock setting the timestamp, the time is coming from the visitor&#8217;s system, which can&#8217;t be trusted to be accurate.  Merely changing the comment form to use JavaScript to generate the first timestamp wouldn&#8217;t work, because verifying a timestamp generated on the client-side against one generated with a server-side language would be disastrous.</p>
<p>Replacing the PHP-generated timestamps with JavaScript-generated timestamps would require substantial changes to the system.</p>
<p>Traditional client-side form validation using JavaScript happens when the form is submitted.  If the validation fails, the form is not submitted, and the visitor typically gets an alert with suggestions on how to make the form acceptable.  If the validation passes, the form submission continues without bothering the visitor.  To get our two timestamps, we can generate a first timestamp when the page loads and compare it to a second timestamp generated when the form is submitted.  If the visitor submits the form too quickly, we can display an alert showing the number of seconds remaining until the form can be successfully submitted.  This should hopefully be invisible to most visitors who choose to leave comments, but at the very least, far less irritating than a CAPTCHA system.</p>
<p>It took me two tries to get it right, but I&#8217;m going to discuss the less successful method first to point out its flaws.</p>
<h3>Method One (not good enough)</h3>
<p>Here&#8217;s how the original system flowed.</p>
<ol>
<li>Generate a first JS timestamp when the page is loaded.</li>
<li>Generate a second JS timestamp when the form is submitted.</li>
<li>Before the form is submitted, compare the two, and if enough time has passed, write a pre-determined passcode to a hidden INPUT element, then submit the form.</li>
<li>On the form processing page, use server-side logic to verify that the passcode is present and valid.</li>
</ol>
<p>The problem was that it seemed that certain bots could parse JavaScript enough to drop the pre-determined passcode into the hidden form field before submitting the form, circumventing the timestamps completely and defeating the system.  </p>
<p>It also failed to adhere to one of the basic tenants of form validation &#8211; that the input must be checked on both the client-side and the server-side.</p>
<h3>Method Two (better)</h3>
<p>Rather than having the server-side validation be merely a check to confirm that the passcode is present, method two goes back to comparing the timestamps a second time on the server side. Instead of a single hidden input, we now have two &#8211; one for each timestamp.  This is intended to prevent a bot from figuring out the ultimate validation mechanism by simply parsing the JavaScript.  Finally, the hidden fields are added to the form via jQuery, which makes it easier to implement and may act as another layer of obfuscation. </p>
<ol>
<li>Generate a first JS timestamp when the page is loaded and write it to a hidden form field.</li>
<li>Generate a second JS timestamp when the form is submitted and write it to a hidden form field.</li>
<li>Before the form is submitted, compare the two, and if enough time has passed, submit the form (client-side validation).</li>
<li>On the form processing page, use server-side logic to compare the timestamps a second time (server-side validation).</li>
</ol>
<p>The timestamp handshake works more like it did in the server-side-only method.  We still have to pass something from the comment form to the processing script, but it&#8217;s not too obvious from the HTML what is being done with it.</p>
<h2>The same downside plagues me</h2>
<p>Unfortunately, if we want to have any server-side validation at all, and we do, the core file <strong>wp-comments-post.php</strong> will still have to be modified.  In my experience, the system is not sufficiently effective using just client-side validation.  </p>
<h2>The code</h2>
<p>Two files must be modified to implement the validation.</p>
<p><strong>File 1: The theme&#8217;s comments.php file (older themes) or wp-includes\comment-template.php (newer themes)</strong></p>
<p>Your comment form lives somewhere.  My theme is based on Kubrick, the old default WordPress theme, and my comment form is in my theme folder, in a file named <strong>comments.php</strong>.  If your theme is newer and based on the current default theme, twentyeleven, the form is in <strong>wp-includes\comment-template.php</strong>.  If your theme isn&#8217;t based on either of these, all bets are off.  I know it&#8217;s confusing.  Sorry.</p>
<p>Add the JavaScript that creates and populates the timestamp fields.  Be sure to confirm that your comment form has an ID of <strong>commentform</strong>.  I&#8217;m using jQuery to help fire functions when the page loads.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
	ardGenTS1();
});

function ardGenTS1() {
	// prepare the form
	$('#commentform').append('&lt;input type=&quot;hidden&quot; name=&quot;ardTS1&quot; id=&quot;ardTS1&quot; value=&quot;1&quot; /&gt;');
	$('#commentform').append('&lt;input type=&quot;hidden&quot; name=&quot;ardTS2&quot; id=&quot;ardTS2&quot; value=&quot;1&quot; /&gt;');
	$('#commentform').attr('onsubmit', 'return validate()');
	// set a first timestamp when the page loads
	var ardTS1 = (new Date).getTime();
	document.getElementById(&quot;ardTS1&quot;).value = ardTS1;
}

function validate() {
	// read the first timestamp
	var ardTS1 = document.getElementById(&quot;ardTS1&quot;).value;
//	alert ('ardTS1: ' + ardTS1);
	// generate the second timestamp
	var ardTS2 = (new Date).getTime();
	document.getElementById(&quot;ardTS2&quot;).value = ardTS2;
//	alert ('ardTS2: ' + document.getElementById(&quot;ardTS2&quot;).value);
	// find the difference
	var diff = ardTS2 - ardTS1;
	var elapsed = Math.round(diff / 1000);
	var remaining = 10 - elapsed;
//	alert ('diff: ' + diff + '\n\nelapsed:' + elapsed);
	// check whether enough time has elapsed
	if (diff &gt; 10000) {
		// submit the form
		return true;
	}else{
		// display an alert if the form is submitted within 10 seconds
		alert(&quot;This site is protected by an anti-spam feature that requires 10 seconds to have elapsed between the page load and the form submission.\n\nPlease close this alert window.  The form may be resubmitted successfully in &quot; + remaining + &quot; seconds.&quot;);
		// prevent the form from being submitted
		return false;
	}
}
&lt;/script&gt;
</pre>
<p><strong>File 2: The wp-comments-post.php file</strong></p>
<p>The wp-comments-post.php file lives in the root of WordPress and handles the form processing.  We need to add a few lines that check the contents of our new validation input field.</p>
<p>Somewhere after line 53 or so (where <em>$comment_content</em> is defined), insert the following code.</p>
<pre class="brush: php; title: ; notranslate">
$ardTS1 = ( isset($_POST['ardTS1']) ) ? trim($_POST['ardTS1']) : 1;
$ardTS2 = ( isset($_POST['ardTS2']) ) ? trim($_POST['ardTS2']) : 2;
$ardTS = $ardTS2 - $ardTS1;

if ( $ardTS &lt; 10000 ) {
// If the difference of the timestamps is not more than 10 seconds, exit
    wp_die( __('&lt;strong&gt;ERROR&lt;/strong&gt;:  This site uses JavaScript validation to reduce comment spam.  Either your browser has JavaScript disabled, or the comment was not legitimately submitted.') );
}
</pre>
<p>That&#8217;s it.  Not so bad, right?</p>
<h2>Final thoughts</h2>
<p>One advantage to this method over the old PHP-only method is that even if the core file is replaced and the server-side validation is lost, the client-side validation continues to work, perhaps providing some measure of protection.</p>
<p>The method is safe for use with caching systems that create purely static, HTML pages.  I&#8217;ll follow up later and report on how effective it seems to be at stopping spam comments before they get to Akismet (and into the WordPress database).</p>
<p>Now, for a little extra protection, you can rename the <strong>wp-comments-post.php</strong> file and change the path in the comment form&#8217;s action attribute.  I&#8217;ve <a href="http://www.ardamis.com/2010/08/09/reducing-wordpress-spam-comments/">posted logs</a> showing that some bots just try to post spam directly to the <strong>wp-comments-post.php</strong> file, so renaming that file is an easy way to cut down on spam.  Just remember to come back and delete the <strong>wp-comments-post.php</strong> file each time you update WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/08/27/a-cache-proof-method-for-reducing-comment-spam/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OOP PHP Notes</title>
		<link>http://www.ardamis.com/2011/07/30/oop-php-notes/</link>
		<comments>http://www.ardamis.com/2011/07/30/oop-php-notes/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 18:56:43 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1565</guid>
		<description><![CDATA[My notes on learning Object Oriented Programming in PHP.]]></description>
			<content:encoded><![CDATA[<p><strong>Overview of classes and objects</strong></p>
<p>Objects are the building blocks of the application (ie: the workers in a factory)<br />
Classes can be thought of as blueprints for the objects.  Classes describe the objects, which are created in memory.<br />
So, the programmer writes the classes and the PHP interpreter creates the objects from the classes.</p>
<p>A class may contain both variables and functions.<br />
A variable inside a class is called a <em>property</em>.<br />
A function inside a class is called a <em>method</em>.</p>
<p><strong>Instantiation</strong></p>
<p>To create an object, you instantiate a class (you create an instance of the class as an object).<br />
For example, if we have a class named &#8216;person&#8217; and want to instantiate it as the variable $oliver:</p>
<pre class="brush: php; title: ; notranslate">$oliver = new person();</pre>
<p>The variable $oliver is referred to as the &#8216;handle&#8217;.</p>
<p><strong>Accessing properties and methods</strong></p>
<p>To access the properties and methods of a class, we use the object&#8217;s handle, followed by the arrow operator &#8220;-&gt;&#8221;.<br />
For example, if our class has a method &#8216;get_name&#8217;, we can echo that to the page with:</p>
<pre class="brush: php; title: ; notranslate">echo $oliver-&gt;get_name();</pre>
<p>Note that there are no single or double quotes used in instantiating a class or accessing properties and methods of a class.</p>
<p><strong>Constructors</strong></p>
<p>A class may have a special method called a constructor.  The constructor method is called automatically when the object is instantiated.<br />
The constructor method begins with two underscores and the word &#8216;construct&#8217;:</p>
<pre class="brush: php; title: ; notranslate">function __construct($variable) { }</pre>
<p>One can pass values to the constructor method by providing arguments after the class name.<br />
For example, to pass the name &#8220;John Doe&#8221; to the constructor method in the &#8216;person&#8217; class:</p>
<pre class="brush: php; title: ; notranslate">$john = new person(&quot;John Doe&quot;);</pre>
<p><span style="color:#F00">!</span> If a constructor exists and expects arguments, you must instantiate the class with the arguments expected by the constructor.</p>
<p><strong>Access modifiers and visibility declarations</strong></p>
<p>Properties must, and methods may, have one of three access modifiers (visibility declarations): public, protected, and private.<br />
Public: can be accessed from outside the class, eg: $myclass->secret_variable;<br />
Protected: can be accessed within the class and by classes derived from the class<br />
Private: can be accessed only within the class</p>
<p>Declaring a property with var makes the property public.</p>
<p>Methods declared without an explicit access modifier are considered public.</p>
<p><span style="color:#F00">!</span> If you call a protected method from outside the class, any PHP output before the call is still processed, but you get an error message when the interpreter gets to that call:</p>
<pre class="brush: plain; title: ; notranslate">Fatal error: Call to protected method...</pre>
<p><strong>Inheritance</strong></p>
<p>Inheritance allows a child class to be created from a parent class, whereby the child has all of the public and protected properties and methods of the parent.</p>
<p>A child class <em>extends</em> a parent class:</p>
<pre class="brush: php; title: ; notranslate">class employee extends person {
}</pre>
<p>A child class can redefine/override/replace a method in the parent class by reusing the method name.</p>
<p><span style="color:#F00">!</span>  A child class&#8217;s method&#8217;s access modifier can not be more restrictive than that of the parent class.  For example, if the parent class has a public set_name() method and the child class&#8217;s set_name() method is protected, the class itself will generate a fatal error, and no prior PHP output will be rendered. (In the error below, <em>employee</em> is the child class to <em>person</em>):</p>
<pre class="brush: plain; title: ; notranslate">Fatal error: Access level to employee::set_name() must be public (as in class person) in E:\xampp\htdocs\tester\oop\class_lib.php on line 38</pre>
<p>To differentiate between a method in a parent class vs the method as redefined in a child class, one must specifically name the class that contains the method you want to call using the scope resolution operator (::):</p>
<pre class="brush: php; title: ; notranslate">person::set_name($new_name);</pre>
<p>The scope resolution operator allows access to static, constant, and overridden properties or methods of a class, generally, a parent class. This would be done inside the child class, after redefining a parent&#8217;s method of the same name.</p>
<p>It&#8217;s also possible to use &#8216;parent&#8217; to refer to the child&#8217;s parent class:</p>
<pre class="brush: php; title: ; notranslate">parent::set_name($new_name);</pre>
<p>(I&#8217;m still a bit vague on this and am looking for examples of situations in which this would be used.)</p>
<p><strong>Classes inside classes</strong></p>
<p>Just as it&#8217;s possible to instantiate a class and use the object in a view file, it&#8217;s possible to instantiate an object and call its methods from inside another class.</p>
<p><strong>Static properties and methods</strong></p>
<p>Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. A property declared as static can not be accessed with an instantiated class object (though a static method can).</p>
<p><strong>Resources</strong><br />
<a href="http://us2.php.net/manual/en/language.oop5.php" title="http://us2.php.net/manual/en/language.oop5.php">http://us2.php.net/manual/en/language.oop5.php</a><br />
<a href="http://net.tutsplus.com/tutorials/php/oop-in-php/" title="http://net.tutsplus.com/tutorials/php/oop-in-php/">http://net.tutsplus.com/tutorials/php/oop-in-php/</a><br />
<a href="http://www.phpfreaks.com/tutorial/oo-php-part-1-oop-in-full-effect" title="http://www.phpfreaks.com/tutorial/oo-php-part-1-oop-in-full-effect">http://www.phpfreaks.com/tutorial/oo-php-part-1-oop-in-full-effect</a><br />
<a href="http://www.killerphp.com/tutorials/object-oriented-php/" title="http://www.killerphp.com/tutorials/object-oriented-php/">http://www.killerphp.com/tutorials/object-oriented-php/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/07/30/oop-php-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jealous of The Social Network</title>
		<link>http://www.ardamis.com/2011/06/12/jealous-of-the-social-network/</link>
		<comments>http://www.ardamis.com/2011/06/12/jealous-of-the-social-network/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 02:46:50 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web app]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1467</guid>
		<description><![CDATA[A short list of my programming accomplishments.]]></description>
			<content:encoded><![CDATA[<p>So I finally watched <a href="http://en.wikipedia.org/wiki/The_Social_Network"><em>The Social Network</em></a> over the weekend, and it&#8217;s made me feel jealous and a bit guilty.</p>
<p>In a meager effort to console myself for so far failing to be a billionaire, I&#8217;m assembling the short list of web-application type things I&#8217;ve built here.</p>
<ol>
<li>A dice roller: <a href="http://alephstudios.com/rollforit/">rollforit</a>. Enter a name, create a room, invite your friends, and start rolling dice.  For people who want to play pen and paper, table-top RPG dice games with their distant friends.</li>
<li>A URL shortener: <a href="http://minifi.de/">Minifi.de</a>.  Minifi.de comes with an API and a bookmarklet.  It really works, too!  The <a href="http://minifi.de/technical.php">technical explanation</a> has more details.</li>
<li>A social networking site: <a href="http://alephstudios.com/snapbase/">Snapbase</a>.  Snapbase is a social site that shows you what&#8217;s going on in your city or anywhere in the world as pictures are uploaded by your friends and neighbors.  The application extracts location information from the EXIF data embedded in images and displays recent images taken near your present location.</li>
<li>A <a href="http://alephstudios.com/helpdesk/">trouble-ticketing system</a> for an IT help desk or technical support center.  It&#8217;s really pretty extensive, with asset management, user accounts, salted encrypted passwords, and all sorts of nifty things.  I really must write a full description of it at some point, but until then, the <a href="http://alephstudios.com/helpdesk/documentation/">documentation</a> is the next best thing.</li>
<li>An <a href="http://alephstudios.com/ias/">account-based invoice tracking and access system</a> for grouping invoices according to clients, then sharing invoice history with those clients and allowing them to easily pay outstanding invoices via Paypal.</li>
<li>An <a href="http://alephstudios.com/ias/">account-based invoice access system</a> where clients can view paid and unpaid invoices, and even easily pay an outstanding invoice via Paypal. I actually use this almost every day.</li>
<li>A simple method for <a href="http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/">protecting a download using a unique URL</a> that can be emailed to authorized users. The URL can be set to expire after a certain amount of time or any number of downloads.</li>
<li>An update to the above download protection script to <a href="http://www.ardamis.com/2009/06/26/protecting-multiple-downloads-using-unique-urls/">protect multiple downloads</a>, generate batches of keys, leave notes about who received the key, the ability to specify per-key the allowable number of downloads and age, and some basic reporting.</li>
<li>An HTML auction template generator called <a href="http://simpleauctionwizard.com/">Simple Auction Wizard</a>.  It helps you create HTML auction templates for eBay, and uses SWFUpload and tinyMCE.</li>
</ol>
<p>I have another project in the works that promises to be more financially viable, but the most clever thing on that list is Snapbase.  It&#8217;s in something akin to alpha right now; barely usable.  I really wish I had the time to pursue it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/06/12/jealous-of-the-social-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fix the &#8220;PHP Fatal error:  Call to undefined function  get_header()&#8221; error in WordPress</title>
		<link>http://www.ardamis.com/2011/06/02/fix-for-php-fatal-error-get_header-in-wordpress/</link>
		<comments>http://www.ardamis.com/2011/06/02/fix-for-php-fatal-error-get_header-in-wordpress/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 17:07:13 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[500 error]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1430</guid>
		<description><![CDATA[Fix the "PHP Fatal error: Call to undefined function get_header()" error in WordPress.]]></description>
			<content:encoded><![CDATA[<p>While making changes to my WordPress theme, I noticed that the error_log file in my theme folder contained dozens of PHP Fatal error lines:</p>
<pre class="brush: plain; title: ; notranslate">
...
[01-Jun-2011 14:25:15] PHP Fatal error:  Call to undefined function  get_header() in /home/accountname/public_html/ardamis.com/wp-content/themes/ars/index.php on line 7
[01-Jun-2011 20:58:23] PHP Fatal error:  Call to undefined function  get_header() in /home/accountname/public_html/ardamis.com/wp-content/themes/ars/index.php on line 7
...
</pre>
<p>The first seven lines of my theme&#8217;s index.php file:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php ini_set('display_errors', 0); ?&gt;
&lt;?php
/**
 * @package WordPress
 * @subpackage Ars_Theme
*/
get_header(); ?&gt;
</pre>
<p>I realized that the error was being generated each time that my theme&#8217;s index.php file was called directly, and that the error was caused by the theme&#8217;s inability to locate the WordPress <strong>get_header</strong> function (which is completely normal).  Thankfully, the descriptive error wasn&#8217;t being output to the browser, but was only being logged to the error_log file, due to the inclusion of the <strong>ini_set(&#8216;display_errors&#8217;, 0);</strong> line.  I had learned this the hard way a few months ago when I found that calling the theme&#8217;s index.php file directly would generate an error message, output to the browser, that would reveal my hosting account username as part of the absolute path to the file throwing the error.</p>
<p>I decided the best way to handle this would be to check to see if the file could find the <strong>get_header</strong> function, and if it could not, simply redirect the visitor to the site&#8217;s home page.  The code I used to do this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php ini_set('display_errors', 0); ?&gt;
&lt;?php
/**
* @package WordPress
* @subpackage Ars_Theme
*/
if (function_exists('get_header')) {
	get_header();
}else{
    /* Redirect browser */
    header(&quot;Location: http://&quot; . $_SERVER['HTTP_HOST'] . &quot;&quot;);
    /* Make sure that code below does not get executed when we redirect. */
    exit;
}; ?&gt;
</pre>
<p>So there you have it.  No more fatal errors due to <strong>get_header</strong> when loading the WordPress theme&#8217;s index.php file directly.  And if something else in the file should throw an error, <strong>ini_set(&#8216;display_errors&#8217;, 0);</strong> means it still won&#8217;t be sent to the browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/06/02/fix-for-php-fatal-error-get_header-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Online tools for detecting malware on web sites</title>
		<link>http://www.ardamis.com/2011/05/07/detecting-malware-on-web-sites/</link>
		<comments>http://www.ardamis.com/2011/05/07/detecting-malware-on-web-sites/#comments</comments>
		<pubDate>Sat, 07 May 2011 18:48:22 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1275</guid>
		<description><![CDATA[Online tools for detecting infections on web sites and for identifying vulnerabilites.]]></description>
			<content:encoded><![CDATA[<p>Just a few notes to myself about monitoring web sites for infections/malware and potential vulnerabilities.</p>
<h2>Tools for detecting infections on web sites</h2>
<h3>Google Webmaster Tools</h3>
<p>Your first stop should be here, as I&#8217;ve personally witnessed alerts show up in Webmaster Tools, even when all the following tools gave the site a passing grade.  If your site is registered here, and Google finds weird pages on your site, an alert will appear.  You can also have the messages forwarded to your email account on file, by choosing the Forward option under the All Messages area of the Home page.</p>
<div id="attachment_1382" class="wp-caption aligncenter" style="width: 784px"><a href="http://www.ardamis.com/wp-content/uploads/2011/05/google-webmaster-tools-hack-alert.png"><img src="http://www.ardamis.com/wp-content/uploads/2011/05/google-webmaster-tools-hack-alert.png" alt="" title="google-webmaster-tools-hack-alert" width="774" height="435" class="size-full wp-image-1382" /></a><p class="wp-caption-text">Google Webmaster Tools Hack Alert</p></div>
<h3>Google Safe Browsing</h3>
<p>The Google Safe Browsing report for ardamis.com: <a href="http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=ardamis.com">http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=ardamis.com</a></p>
<h3>Norton Safe Web</h3>
<p><a href="https://safeweb.norton.com/">https://safeweb.norton.com/</a></p>
<p>The Norton Safe Web report for ardamis.com: <a href="https://safeweb.norton.com/report/show?url=ardamis.com">https://safeweb.norton.com/report/show?url=ardamis.com</a></p>
<h2>Tools for analyzing a site for vulnerabilities</h2>
<h3>Sucuri Site Check</h3>
<p><a href="http://sitecheck.sucuri.net/scanner/">http://sitecheck.sucuri.net/scanner/</a></p>
<p>The Sucuri report for ardamis.com: <a href="http://sitecheck.sucuri.net/scanner/?scan=www.ardamis.com">http://sitecheck.sucuri.net/scanner/?scan=www.ardamis.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/05/07/detecting-malware-on-web-sites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Online tools for testing web page performance</title>
		<link>http://www.ardamis.com/2011/04/10/online-tools-for-testing-web-page-performance/</link>
		<comments>http://www.ardamis.com/2011/04/10/online-tools-for-testing-web-page-performance/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 02:49:53 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=816</guid>
		<description><![CDATA[A collection of online tools for measuring the performance of web pages, including time to first byte.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a few tutorials lately on how to reduce page load times.  While I use Google&#8217;s Page Speed Firefox/Firebug plugin for evaluating pages for load times, there are times when I want a second opinion, or want to point a client to a tool.  This post is a collection of links to online tools for testing web page performance.</p>
<h2>Page Speed Online</h2>
<p><a href="http://pagespeed.googlelabs.com/">http://pagespeed.googlelabs.com/</a></p>
<p>Google&#8217;s wonderful Page Speed tool, once only available as a Firefox browser Add-on, finally arrives as an online tool.  Achieving a high score (ardamis.com is a 96/100) should be on every web developer&#8217;s list of things to do before the culmination of a project.</p>
<p>Enter a URL and Page Speed Online will run performance tests based on a set of best practices known to reduce page load times.</p>
<p>Optimizing caching &#8211; keeping your application&#8217;s data and logic off the network altogether<br />
Minimizing round-trip times &#8211; reducing the number of serial request-response cycles<br />
Minimizing request overhead &#8211; reducing upload size<br />
Minimizing payload size &#8211; reducing the size of responses, downloads, and cached pages<br />
Optimizing browser rendering &#8211; improving the browser&#8217;s layout of a page</p>
<h2>WebPagetest</h2>
<p><a href="http://www.webpagetest.org/">http://www.webpagetest.org/</a></p>
<p>WebPagetest is an excellent application for users who want the same sort of detailed reporting that one gets with Page Speed.</p>
<p>Load time speed test on first view (cold cache) and repeat view (hot cache), first byte and start render<br />
Optimization checklist<br />
Enable keep-alive, HTML compression, image compression, cache static content, combine JavaScript and CSS, and use of CDN<br />
Waterfall<br />
Response headers for each request</p>
<h2>Load Impact</h2>
<p><a href="http://loadimpact.com/pageanalyzer.php">http://loadimpact.com/pageanalyzer.php</a></p>
<p>Load Impact is an online load testing service that lets you load- and stress test your website over the Internet.  The page analyzer analyzes your web page performance by emulating how a web browser would load your page and all resources referenced in it. The page and its referenced resources are loaded and important performance metrics are measured and displayed in a load-bar diagram along with other per-resource attributes such as URL, size, compression ratio and HTTP status code.</p>
<h2>ByteCheck</h2>
<p><a href="http://www.bytecheck.com/">http://www.bytecheck.com/</a></p>
<p>ByteCheck is a super minimal site that return your page&#8217;s all-important time to first byte (TTFB). Time to first byte is the time it takes for a browser to start receiving information after it has started to make the request to the server, and is responsible for a visitor&#8217;s first impression that a page is fast- or slow-loading.</p>
<h2>Web Page Analyzer</h2>
<p><a href="http://websiteoptimization.com/services/analyze/">http://websiteoptimization.com/services/analyze/</a></p>
<p>My opinion is that the Web Page Analyzer report is good for beginners without much technical knowledge of things like gzip compression and Expires headers.  It&#8217;s a bit dated, and is primarily concerned with basics like how many images a page contains.  It tells you how fast you can expect your page to load for dial-up visitors, which strikes me as quaint and not particularly useful.</p>
<p>Total HTTP requests<br />
Total size<br />
Total size per object type (CSS, JavaScript, images, etc.)<br />
Analysis of number of files and file size as compared to recommended limits.</p>
<h2>The Performance Grader</h2>
<p><a href="http://www.joomlaperformance.com/component/option,com_performance/Itemid,52/">http://www.joomlaperformance.com/component/option,com_performance/Itemid,52/</a></p>
<p>This is another simplistic analysis of a site, like Web Page Analyzer, that returns its analysis in the form of pass/fail grades on about 14 different tests.  I expect that it would be useful for developers who want to show a client a third-party&#8217;s analysis of their work, if the third-party is not terribly technically savvy.  </p>
<p>One unique thing about this tool, though, is that it totals up the size of all images referenced in CSS files (even those that the current page isn&#8217;t using).</p>
<p>HTML Size<br />
Total Size<br />
Total Requests<br />
Generation Time<br />
Number of Hosts<br />
Number of Images<br />
Size of Images<br />
Number of CSS Files<br />
Size of CSS Files<br />
Number of Script Files<br />
Size of Script Files<br />
HTML Encoding<br />
Valid HTML<br />
Frames</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2011/04/10/online-tools-for-testing-web-page-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>301 Redirect in Classic ASP</title>
		<link>http://www.ardamis.com/2010/11/22/301-redirect-in-classic-asp/</link>
		<comments>http://www.ardamis.com/2010/11/22/301-redirect-in-classic-asp/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 23:14:39 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Web Site Dev]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=1140</guid>
		<description><![CDATA[How to implement a 301 redirect in Classic ASP.]]></description>
			<content:encoded><![CDATA[<p>I have to look up how to implement a 301 redirect in ASP every few months, so I&#8217;m putting this up as a personal reference.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;%@ Language=&quot;VBScript&quot; %&gt;
&lt;%
Response.Status = &quot;301 Moved Permanently&quot;
Response.AddHeader &quot;Location&quot;, &quot;http://domain.com/page.asp&quot;
Response.End
%&gt;
</pre>
<p>It seems that the value of Location can be a relative path and the redirect will still function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2010/11/22/301-redirect-in-classic-asp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to clean up those Mac OSX hidden files</title>
		<link>http://www.ardamis.com/2010/08/10/clean-up-those-mac-osx-hidden-files/</link>
		<comments>http://www.ardamis.com/2010/08/10/clean-up-those-mac-osx-hidden-files/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 06:20:19 +0000</pubDate>
		<dc:creator>ardamis</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Nonsense]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://www.ardamis.com/?p=941</guid>
		<description><![CDATA[How to delete the hidden files that Mac OSX puts on flash drives, USB hard drives, and other shared storage.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a simple batch file to remove those hidden files that Mac OSX leaves all over shared drives to annoy us Windows users.</p>
<pre class="brush: php; title: ; notranslate">
del /s /a:h ._*
:: http://en.wikipedia.org/wiki/Resource_fork

del /s /a:h .DS_Store
:: http://en.wikipedia.org/wiki/.DS_Store

del /s /a:h .Trashes
:: http://en.wikipedia.org/wiki/Recycle_bin_(computing)

@pause
</pre>
<h2>How to use</h2>
<p>Copy the code into a text file, rename it <strong>cleanOSX.bat</strong> and run it from the root of the drive you wish to clean.  The script will look through all subfolders, deleting any hidden file or folder with a name that begins with <strong>._</strong>, or that matches <strong>.DS_Store</strong> or <strong>.Trashes</strong>.  Depending on the number of these files on your drive, the process of deleting them could take some time.</p>
<h2>Where do these files come from?</h2>
<h3>The resource fork</h3>
<blockquote><p>The resource fork is a construct of the Mac OS operating system used to store structured data in a file, alongside unstructured data stored within the data fork. A resource fork stores information in a specific form, such as icons, the shapes of windows, definitions of menus and their contents, and application code (machine code). For example, a word processing file might store its text in the data fork, while storing any embedded images in the same file&#8217;s resource fork. The resource fork is used mostly by executables, but every file is able to have a resource fork.<br />
&#8230;<br />
Currently, Mac OS X does support resource forks on Windows SMB shares by creating a hidden file in the same directory with the data fork file, with the characters “._” at the beginning of the file name. However, this may be annoying for some users, especially because some Windows power users always keep hidden files visible. Besides, Windows does not treat those files correctly as the file itself is moved or removed.</p>
<p><a href="http://en.wikipedia.org/wiki/Resource_fork">http://en.wikipedia.org/wiki/Resource_fork</a></p></blockquote>
<h3>The Desktop Services Store</h3>
<blockquote><p>.DS_Store (Desktop Services Store) is a hidden file created by Apple Inc.&#8217;s Mac OS X operating system to store custom attributes of a folder such as the position of icons or the choice of a background image.</p>
<p><a href="http://en.wikipedia.org/wiki/.DS_Store">http://en.wikipedia.org/wiki/.DS_Store</a>
</p></blockquote>
<h3>The Trash folder</h3>
<blockquote><p>Under Mac OS X, when a file is deleted in Finder, it is moved to a .Trashes folder, and when viewing the device&#8217;s available space the space occupied by the deleted files is shown as occupied.</p>
<p><a href="http://en.wikipedia.org/wiki/Recycle_bin_(computing)">http://en.wikipedia.org/wiki/Recycle_bin_(computing)</a>
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.ardamis.com/2010/08/10/clean-up-those-mac-osx-hidden-files/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

