<?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>Andrew's Tech Musings &#187; Andrew Curioso</title>
	<atom:link href="http://andrewcurioso.com/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewcurioso.com</link>
	<description>Tech, Social Media, PHP, Opinions</description>
	<lastBuildDate>Wed, 14 Jul 2010 22:18:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Authentication vs. Authorization</title>
		<link>http://andrewcurioso.com/2010/07/authentication-vs-authorization/</link>
		<comments>http://andrewcurioso.com/2010/07/authentication-vs-authorization/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 19:03:40 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=402</guid>
		<description><![CDATA[This seems like a no-brain-er but I have seen it more times than I can count and I have seen it happen to some very experienced developers. Put simply: authentication is not enough; you need to make sure that the authenticated user is actually authorized to perform an action. It is one thing to know [...]]]></description>
			<content:encoded><![CDATA[<p>This seems like a no-brain-er but I have seen it more times than I can count and I have seen it happen to some very experienced developers. Put simply: <strong>authentication</strong> is not enough; you need to make sure that the authenticated user is actually <strong>authorized</strong> to perform an action. It is one thing to know who a user is and an entirely different &#8212; though equally important &#8212; thing to know what a user is allowed to do.</p>
<p>This article covers the concepts of authentication and authorization.</p>
<p><span id="more-402"></span></p>
<p>Authentication is knowing who the logged in user is. Authorization is knowing what the user can and can&#8217;t do and can be as easy as checking that the user ID in the database matches the user ID of the authenticated user. It can also be as complex  as Access Control Lists, social graphs, and multi-moderator systems. Either way it needs to be taken care of. Very few things are more devastating than when a malicious user finds that all you have to do to edit another user&#8217;s data is to change the value of a POST variable or all you need to do to access someone&#8217;s private photos is to change a URL. Do either of those two cases sound familiar?</p>
<h2>Thinking like a hacker</h2>
<blockquote><p>
If I were to try to exploit this feature: how would I go about it?<br />
<span class="citation">you, every time you write code (hopefully)</span>
</p></blockquote>
<p>Let&#8217;s start by looking at a imaginary site that makes an Ajax request to delete a resource via a RESTful API. The HTTP request probably looks a bit like this:</p>
<pre class="brush: plain;">
POST /resources/1234.json HTTP/1.1
Host: www.example.com
Content-Length: 14

_method=DELETE
</pre>
<p>Now, make the assumption that you can find the ID of any resource on the system. This could be because it is exposed in a &#8220;view&#8221; URL or it could be that it is returned in an API call for search. Either way, assume that if it exists a hacker can find it either by design or through flaws in the code. Never assume primary keys are a secret. The next step is to find an ID of a resource not owned by the hacker (in this example: 5678) and to go the command line (assuming cURL is installed on your system):</p>
<pre class="brush: plain;">
curl -d &quot;_method=delete&quot; http://www.example.com/resources/5678.json
</pre>
<p>Curl doesn&#8217;t share cookies with the web browser so if that call succeeded and record 5678 was actually deleted then the application is not checking to see if the user is <strong>authenticated</strong>. There is no need to go any further, you&#8217;ve already found a devastating exploit. If this is your application (I hope that you aren&#8217;t using this article to try to hack other people&#8217;s apps!) it is time to go back to the code, add a check to make sure that the user is logged in. Then come back here to read on.</p>
<p>If the call didn&#8217;t work then it is time to try to delete the resource as an authenticated (but hypothetically not authorized) user:</p>
<pre class="brush: plain;">
curl -d &quot;username=you&amp;password=abcdefg&quot; -c &quot;cookies.txt&quot; http://www.example.com/login/
curl -d &quot;_method=delete&quot; -b &quot;cookies.txt&quot; http://www.example.com/resources/5678.json
</pre>
<p>The first line authenticates the user and stores the cookies. The second line tries the delete method again with the new cookies. Make sure to replace all the appropriate variables and URLs in all of these examples. If all went <del>well</del> bad the resource 5678 should now be deleted. If that happened then the application needs to check for <strong>authorization</strong> as well as authentication.</p>
<p>The same concepts can be applied to viewing, editing, and creating resources. This article uses cURL but there are numerous other ways of spoofing Ajax and API requests, including injecting Javascript into the browser and writing a PHP / Perl / Ruby / Python / etc. script to do it.</p>
<p class="pitfall">One thing to watch out for is any request that takes the user ID as a parameter. It should raise a red flag. Whenever possible, get the user ID from the currently authenticated user. I once saw a password vault web application that returned the entire password list from a SOAP call given only the user ID. Just so you are sufficiently mortified, I&#8217;ll rephrase it: I could enter in any user&#8217;s ID and get back a list of passwords for other sites on the Internet (including Google). Don&#8217;t let that happen to you!</p>
<h2>Taking care of business</h2>
<p>Addressing the problem takes as much thought and planning then actually technical know-how. Imagine a user for each role (resource owner, administrator, moderator, customer support, friend of the user &#8212; if you are a social network &#8212; etc.) then ask three questions:</p>
<ol>
<li>User X can/can&#8217;t view resource Y because&#8230;</li>
<li>User X can/can&#8217;t edit resource Y because&#8230;</li>
<li>User X can/can&#8217;t delete resource Y because&#8230;</li>
</ol>
<p>Then for each of those, check to make sure the code reinforces that statement. It is also a good idea to give these stories to the testers and have them try to break your code. And remember: the authentication system tells you WHO the user is and authorization system tells you WHAT actions the user can perform.</p>
<p>How complex a system you need for authorization depends on your application. It can range from one-off code to full-featured generic systems that can be used for any type of resource imaginable. Social networks are the most complicated of the bunch because authorization often depends on a personal relationship with the user requesting access to the resource. The simplest form of authentication is:</p>
<pre class="brush: php;">
if ( $user-&gt;id != $resource-&gt;owner_id )
  throw new Exception(&quot;Access denied&quot;);
</pre>
<p>Or if your application is a social network and you give friend&#8217;s access to resources:</p>
<pre class="brush: php;">
if ( $user-&gt;id != $resource-&gt;owner_id &amp;&amp; !$user-&gt;isFriendsWith($resource-&gt;owner_id) )
  throw new Exception(&quot;Access denied&quot;);
</pre>
<p>For a more robust system you&#8217;ll probably want to implement an Access Control List (ACL). An ACL at its core is just a mapping of users to resources. For example: Joe has view, edit, and delete access to resource 1234.</p>
<p>More advanced access control lists also have groups (called &#8220;roles&#8221;) and they can cascade. Roles introduce some ambiguity, and multiple entries in the list may govern the same action. If that happens, the most specific one is taken. For example, editing a resource may be governed by the rules:</p>
<ul>
<li>&#8220;Joe&#8221; is in the group &#8220;Basic Users&#8221; and &#8220;Basic Users&#8221; explicitly can NOT edit resources of type &#8220;forum post&#8221;
	</li>
<li>&#8220;Joe&#8221; CAN edit resources of type &#8220;forum post&#8221; with ID &#8220;1234&#8243;
</li>
</ul>
<p>Since Joe has edit rights to the forum post with an ID of 1234 it doesn&#8217;t matter that the role Joe plays (a &#8220;Basic User&#8221;) cannot edit any forum posts.  There are numerous articles on implementing an ACL in a PHP application and many frameworks have built-in classes for ACL.</p>
<h2>Summary</h2>
<p>When developing web applications (or any application for that matter): always be cognizant of authentication and authorization. Remember, authentication answers the question of WHO and authorization answers the question of WHAT. The application must always know the answer to both of those questions and be able to deny or allow certain actions based on those answers. It might be useful for newer developers to to actually put themselves in the shoes of a hacker and attempt to find exploits for their own website. Eventually, it will become second nature.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2010/07/authentication-vs-authorization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakeFest 2010 &#8211; Chicago, IL</title>
		<link>http://andrewcurioso.com/2010/06/cakefest-2010/</link>
		<comments>http://andrewcurioso.com/2010/06/cakefest-2010/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 15:39:28 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=333</guid>
		<description><![CDATA[CakeFest is an annual gathering of CakePHP developers. This year&#8217;s conference is being held in Chicago, IL from September 2nd to the 5th. I will be presenting a talk on API Development. As the conference gets closer I will update this page with outlines, links, downloads, and eventually the final presentation. You can view the [...]]]></description>
			<content:encoded><![CDATA[<p>CakeFest is an annual gathering of CakePHP developers. This year&#8217;s conference is being held in Chicago, IL from September 2nd to the 5th.</p>
<p>I will be presenting a talk on API Development. As the conference gets closer I will update this page with outlines, links, downloads, and eventually the final presentation.</p>
<p><span id="more-333"></span></p>
<p>You can <a href="http://cakefest.org/schedule">view the complete schedule</a> or <a href="http://cakefest.org/ticket-info">register for the event</a> and find a lot of other useful information on the <a href="http://cakefest.org/">CafeFest website</a>.</p>
<p><script type="text/javascript">
$(function () {
	var cakeFest = new Date("2 Sep 2010 8:00:00 CDT")
	$('#cakeFestCountdown').countdown({until: cakeFest, format: 'dHM'});
});
</script></p>
<p style="margin-bottom: 0px;">Doors open at CakeFest 2010</p>
<div id="cakeFestCountdown" style="width: 200px"></div>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2010/06/cakefest-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting file size overflow in PHP</title>
		<link>http://andrewcurioso.com/2010/06/detecting-file-size-overflow-in-php/</link>
		<comments>http://andrewcurioso.com/2010/06/detecting-file-size-overflow-in-php/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 03:55:06 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=232</guid>
		<description><![CDATA[One of the things that separates a good web application from a great one is how gracefully they handle failures. One of the often overlooked cases is when a user attempts to upload a file that exceeds the set PHP upload file size. This article shows how to detect when the user tries to upload [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that separates a good web application from a great one is how gracefully they handle failures. One of the often overlooked cases is when a user attempts to upload a file that exceeds the set PHP upload file size. This article shows how to detect when the user tries to upload a file that is too large and display an appropriate message.<br />
<span id="more-232"></span><br />
This article assumes that you have already set upload_max_filesize, post_max_size, and memory_limit in your php.ini file to appropriate values. It also assumes that you already have a working file upload form. There are plenty of tutorials out there already to get you started. </p>
<p>If you can, you may want to set post_max_size to a low value (say &#8220;1M&#8221;) to make testing easier. </p>
<p>First test to see how your script behaves. Try uploading a file that is larger than post_max_size. If you do you will get a message like this in your error log:</p>
<pre class="brush: plain;">
[09-Jun-2010 19:28:01] PHP Warning:  POST Content-Length of 30980857 bytes exceeds the limit of 2097152 bytes in Unknown on line 0
</pre>
<p>If you&#8217;re not careful this can lead to unexpected behavior in your application. The end result can range from silent failure all the way to lost customers.</p>
<h2>Solving the problem</h2>
<p>The PHP documentation provides a hack to solve this problem:</p>
<blockquote><p>If the size of post data is greater than post_max_size, the $_POST and $_FILES  superglobals  are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. &lt;form action=&#8221;edit.php?processed=1&#8243;&gt;, and then checking if $_GET['processed'] is set.<br />
<a href="http://php.net/manual/en/ini.core.php" class="citation">Source: PHP manual</a></p></blockquote>
<p>To be clear, it is suggesting that you pass a value in the query string along with your form. If the value is in the $_GET superglobal and both $_FILE and $_POST are empty then the maximum upload size is exceeded. There are two problems with this approach: it adds extra complexity on the front-end and it can potential give a false positive.</p>
<p>Extra complexity on the front-end means extra documentation and more room for mistakes. And if there is a mistake it may not be caught for a long time (does your QA team routinely upload large files?).  In this case we already have all the data that we need to determine if the maximum file size was exceeded without adding extra complexity and headache for developers.</p>
<p>We know what type of request is being processed, we have the $_POST and $_FILES arrays, and we have the content length as it was passed to the HTTP server from the client.  From that we get this code:</p>
<pre class="brush: php;">
if ( $_SERVER['REQUEST_METHOD'] == 'POST' &amp;&amp; empty($_POST) &amp;&amp;
     empty($_FILES) &amp;&amp; $_SERVER['CONTENT_LENGTH'] &gt; 0 )
{
  $displayMaxSize = ini_get('post_max_size');

  switch ( substr($displayMaxSize,-1) )
  {
    case 'G':
      $displayMaxSize = $displayMaxSize * 1024;
    case 'M':
      $displayMaxSize = $displayMaxSize * 1024;
    case 'K':
       $displayMaxSize = $displayMaxSize * 1024;
  }

  $error = 'Posted data is too large. '.
           $_SERVER[CONTENT_LENGTH].
           ' bytes exceeds the maximum size of '.
           $displayMaxSize.' bytes.&quot;;
}
</pre>
<p>The important thing to notice is the &#8220;if&#8221; statement on lines one and two. The example code just sets an error string. Production code might display a message to the user, execute some Javascript (for asynchronous uploads), or pass back a XML or Json object for Flash clients.</p>
<p>I&#8217;ve tested this code with Apache as both a module and as CGI. As far as I know it should work fine with IIS as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2010/06/detecting-file-size-overflow-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Expert PHP and MySQL</title>
		<link>http://andrewcurioso.com/2010/02/expert-php-and-mysql/</link>
		<comments>http://andrewcurioso.com/2010/02/expert-php-and-mysql/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 20:34:17 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=185</guid>
		<description><![CDATA[Expert PHP and MySQL is a perfect book for advanced PHP and MySQL programmers who want to take their code to the next level. Some of the topics covered in the book include: PHP Design Patterns Security Writing PHP Extensions Multi-tasking with Gearman Full-text search with Sphinx Writing MySQL UDFs Advanced MySQL Advanced rewrite rules [...]]]></description>
			<content:encoded><![CDATA[<p>Expert PHP and MySQL is a perfect book for advanced PHP and MySQL programmers who want to take their code to the next level.<br />
<span id="more-185"></span></p>
<div style="width: 50%; margin-right: 50%; position: relative;">
Some of the topics covered in the book include:</p>
<ul>
<li>PHP Design Patterns</li>
<li>Security</li>
<li>Writing PHP Extensions</li>
<li>Multi-tasking with Gearman</li>
<li>Full-text search with Sphinx</li>
<li>Writing MySQL UDFs</li>
<li>Advanced MySQL</li>
<li>Advanced rewrite rules and regular expressions</li>
<li>Building command-line applications</li>
<li>SOAP services</li>
<li>RESTful services</li>
<li>more&#8230;</li>
</ul>
<p>Available in stores this now.<br />
<a href="http://www.amazon.com/gp/product/0470563125?ie=UTF8&#038;tag=365note-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0470563125">Pick up your copy today on Amazon.com</a><img src="http://www.assoc-amazon.com/e/ir?t=365note-20&#038;l=as2&#038;o=1&#038;a=0470563125" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />.</p>
<div style="position: absolute; left: 100%; top: 0; width: 100%">
What other people are saying:</p>
<blockquote><p>
For once, an “Expert” book where you not only can, but must take the title seriously.<br />
<a href="http://www.bitbybit.dk/carsten/blog/?p=281" class="citation">Carsten Pedersen</a>
</p></blockquote>
<blockquote><p>
The techniques discussed in this book [are] used by large sites we all know: Digg, Yahoo, Facebook, YouTube and more.. if its [sic] good for them I believe its [sic] good for you too.<br />
<a href="http://blog.umnet.co.il/2010/04/23/book-review-expert-php-and-mysql/" class="citation">Udi Mosayev</a>
</p></blockquote>
<p>If you wrote a review please <a href="/about/contact/">contact me</a> and let me know.
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2010/02/expert-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyVBO &#8211; The Virtual Business Office</title>
		<link>http://andrewcurioso.com/2010/02/myvbo/</link>
		<comments>http://andrewcurioso.com/2010/02/myvbo/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 18:45:42 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=174</guid>
		<description><![CDATA[MyVBO is a business application created by people who know business. It brings all your business needs into one place, including purchasing, stock quotes, Quickbooks, and Twitter. You can try out myVBO for free at www.myVBO.com. I joined the myVBO team in March of 2009. My contributions to the project include: Designed a full featured [...]]]></description>
			<content:encoded><![CDATA[<p>MyVBO is a business application created by people who know business. It brings all your business needs into one place, including purchasing, stock quotes, Quickbooks, and Twitter.</p>
<p><span id="more-174"></span></p>
<p>You can try out myVBO for free at <a href="http://www.myVBO.com">www.myVBO.com</a>.</p>
<p>I joined the myVBO team in March of 2009. My contributions to the project include:</p>
<ul>
<li>Designed a full featured multi-account Twitter client.</li>
<li>Created versatile multi-environment configuration system.</li>
<li>Designed and developed a versatile cross-platform short-polling and batch processing mechanism for dynamic data updates.</li>
<li>Developed a robust platform API (both REST and RPC) as well as ActionScript 3 consumer client libraries.</li>
<li>Created an extensible authentication system ready to accept users from multiple sources.</li>
<li>Developed a user avatar system.
	</li>
<li>Also contributed to: user profiles, product search display, news infrastructure, product planning, and user interface design.</li>
</ul>
<p>Be sure to give it a try if you need a way to keep track of your business online.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2010/02/myvbo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A method called &#8216;delete&#8217; in Flex and AS3</title>
		<link>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/</link>
		<comments>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 05:26:30 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Flex and AS3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=137</guid>
		<description><![CDATA[You are in for a headache if you have try to call a method or create a member variable with the name of a reserved word in Actionscript. It can lead to such fun situations as having variables called: insert; update; deleteSomething. Because calling the third variable &#8220;delete&#8221; may be logical but it is a [...]]]></description>
			<content:encoded><![CDATA[<p>You are in for a headache if you have try to call a method or create a member variable with the name of a reserved word in Actionscript. It can lead to such fun situations as having variables called: insert; update; deleteSomething. Because calling the third variable &#8220;delete&#8221; may be logical but it is a reserved word so that is out of the question. It gets hairier when you don&#8217;t necessarily have control over the object format (such is often the case with remote calls). I ran into this today when trying to call the &#8220;node_delete&#8221; (or &#8220;node.delete&#8221;) method in Drupal via Services and AMFPHP. This is frustrating so I&#8217;m going to show two situations where you could run into this problem and how I fixed them.<br />
<span id="more-137"></span></p>
<h3>Situation #1: A variable named &#8220;new&#8221; in a dynamic class</h3>
<p>You are creating a dynamic object and you need to use a reserved word as a member variable name but you can&#8217;t.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var x:Object = new Object;
x.new = &quot;this doesn't work&quot;;
x['new'] = &quot;this works&quot;;
</pre>
<p></span><br />
The first method is a nice way to get <em>1084: Syntax error: expecting identifier before new</em> when you try to compile. Remove that line and use just the second one and you are all set. It is OK to mix and match access methods, as long as you never use dot notation for reserved words.</p>
<h3>Situation #2: A RPC method named delete</h3>
<p>You are making a remote call via the RemoteObject class (such as I was doing with Drupal) and you need to call a method named &#8220;delete&#8221; (or &#8220;new&#8221; for that matter). You naturally try this:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var ro:RemoteObject = new RemoteObject;
ro.endpoint = &quot;http://www.example.com/amfphp&quot;;
ro.delete( 1234 );
</pre>
<p></span><br />
You will be promptly greeted by the now familiar 1084 error when you try to compile and using a different notation won&#8217;t work. I&#8217;ll break the solution into multiple parts although it could just as easily be chained together:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var op:AbstractOperation = ro.getOperation('delete');
op.send( 12345 );
</pre>
<p></span><br />
Incidentally the result of the &#8220;send&#8221; method is a AsyncToken object (the same object that &#8220;ro.delete()&#8221; would return if delete were not reserved) which can then be used to add responders.</p>
<p>There you have it. Two quick and easy ways to get around methods and properties with reserved words for names.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 things about PHP 5.3 that make me smile</title>
		<link>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/</link>
		<comments>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 03:41:08 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[early adopters]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=89</guid>
		<description><![CDATA[Rest assured. Soon I will be writing &#8220;Things about PHP 5.3 that make me cringe&#8221; but for now I sing the praises of the latest release of PHP that that came out today. I&#8217;ve been playing with the new release for months and there are indeed many good things about it and many of them [...]]]></description>
			<content:encoded><![CDATA[<p>Rest assured. Soon I will be writing &#8220;Things about PHP 5.3 that make me cringe&#8221; but for now I sing the praises of the latest release of PHP that that came out today. I&#8217;ve been playing with the new release for months and there are indeed many good things about it and many of them have been a long time coming.</p>
<p>The other day I was reading the release notes and I couldn&#8217;t help but smile.<br />
<span id="more-89"></span></p>
<h3>1. New native MySQL driver</h2>
<p>I&#8217;m saving the best for last. So bear with me. Lets get through the small grins before we get to the big toothy ones (or you can read ahead&#8230; you&#8217;re choice). PHP 5.3 ships with a new MySQL driver called mysqld. A database driver is responsible for making the actually connection from PHP to MySQL. The previous MySQL driver had some flaws. For one, it was license in a way that was not compatible with the PHP license. The new <em>MySQL Native Driver</em> has a more amicable license (which is big in the open source world). It also adds some experimental functionality including improved persistent connections. There is also a down side but that is for another post.</p>
<h3>2. Host specific PHP INI configurations</h3>
<p>I previously worked on a hosted CMS and web publishing tool that had dozens of virtual hosts but only one php.ini. The new functionality allows to section off your PHP configuration to have a different configuration for every host or file path. I haven&#8217;t tried this one yet so I&#8217;m not sure how well it works. Try it out for yourself. There is a comment on <a href="http://www.php.net/">PHP.net</a> right now saying that it only works for CGI PHP and not for the CLI implementation.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: plain;">
[HOST=example.com]
error_reporting = E_ALL
display_errors = On
</pre>
<p></span><br />
Example from the PHP documentation.</p>
<h3>3. Shortcut ternary operator</h3>
<p>I had never considered this before. However, this saves a lot of time for rather repetitive code. Consider these three identical code snipits.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?php
if ( $foo ) $x = $foo;
else $x = $bar;

$x = ( $foo ? $foo : $bar );
$x = ( $foo ?: $bar );
?&gt;
</pre>
<p></span></p>
<p>The third method is the new shortcut. It reads simply: &#8220;if foo than foo else bar.&#8221; I am still waiting for the first time for this to be useful. The biggest issue I see is that in the above example $foo cannot legitimately be anything that evaluates to false. As a result it is best used for variables that should be non-empty strings or non-zero numbers.</p>
<h3>4. Date math</h3>
<p>The DateTime class now has several new methods in it for dealing with date arithmetic. It puts an end to manually converting to timestamps and back to dates again. It works very simply:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?php
$date = new DateTime('2009-06-30 09:00:00');
$date-&gt;sub('P5D'); // Subtract five days
echo $data-&gt;diff( new DateTime() )-&gt;format('%d').' days ago';
?&gt;
</pre>
<p></span><br />
The new DateTime methods and the new DateInterval class (returned from and passed to math functions) aren&#8217;t very well documented because they are so new.<br />
It is worth noting that the format methods are different in the two classes. Intervals require a percentage (%) in front of placeholders. Watch out for that.</p>
<h3>5. Closures</h3>
<p>Closures are one of the best parts of PHP 5.3. At first I wasn&#8217;t very excited about them. I use closures constantly in Javascript but in a stateless HTTP request situation they appear less useful. But then I got into it. They are improved methods of dealing with lambda-functions. In other words, they are functions that are nameless and can be assigned to variables. In actuality they are classes.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?phpi
$y = 10;
$x = function($number) use ( &amp;$y ) {
  return $number * $y;
};
$y = 100;
echo $x(8); // Output: 800
?&gt;
</pre>
<p></span><br />
This is the point at which a lot of PHP programmers would pause. Did I say they are classes? Since when can you call a class like it was a function? Since PHP 5.3 you can! . You do it by defining the &#8220;_invoke&#8221; magic method. Like so:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?php
class testInvoke {
  public function __invoke( $x ) { echo &quot;Hello $x&quot;; }
};
$x = new TestInvoke();
echo $x('world'); // outputs &quot;Hello World&quot;
?&gt;
</pre>
<p></span><br />
This is by far one of the coolest new features in PHP 5.3. It opens a whole new world of possibilities for clean / manageable code.</p>
<h3>Bonus Things</h3>
<h4>5.1. New magic method for matching calls to static methods</h4>
<p>For a while now we have been able to define the magic method &#8220;__call&#8221; in our classes that will be executed if you try to call a method in a class instance that does not exist. Now the &#8220;__callStatic&#8221; method does the same thing only for methods of static classes.</p>
<h4>5.2. Late static binding</h4>
<p>Late static binding is a long time coming. In fact, this has tripped me up in several projects. In simplest terms late binding is waiting to determine what object a method or member variable belongs to until it is called. Late static binding in PHP, as its name indicates, applies this concept to static methods and members variables in PHP. The PHP.net website bests describes in on the <a href="http://us.php.net/lsb">manual page for late static binding</a>.</p>
<h4>5.3. E_DEPRECATED</h4>
<p>Here is a tip for everyone: if you are developing open source PHP software you should develop it in E_STRICT mode. This new E_DEPRECATED flag is actually part of E_ALL which sends a strong message that you shouldn&#8217;t be using these depreciated functions. I am a huge fan of anything that helps us write better code.</p>
<p>I hope everyone got through this post just fine. It is a long one. Leave comments (the comment section is OpenID enabled).</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Drop shadow tricks in Flex</title>
		<link>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/</link>
		<comments>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 15:20:11 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Flex and AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=53</guid>
		<description><![CDATA[Every display markup language has its frustrating moments. Adobe Flex isn&#8217;t any exception. I ran into a little trouble a while back when trying to put a drop shadow on a HBox component. Here is the effect that I wanted to achieve: It seems easy enough so let&#8217;s give this a try: &#60;mx:Style&#62; HBox { [...]]]></description>
			<content:encoded><![CDATA[<p>Every display markup language has its frustrating moments. Adobe Flex isn&#8217;t any exception. I ran into a little trouble a while back when trying to put a drop shadow on a HBox component. Here is the effect that I wanted to achieve:</p>
<div id="attachment_57" class="wp-caption alignnone" style="width: 321px"><img class="size-full wp-image-57" title="Flex form with drop shadow header" src="http://andrewcurioso.com/wp-content/uploads/2009/05/picture-6.png" alt="Flex form with drop shadow header" width="311" height="216" /><p class="wp-caption-text">Flex form with drop shadow header</p></div>
<p><span id="more-53"></span></p>
<p>It seems easy enough so let&#8217;s give this a try:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: xml;">
&lt;mx:Style&gt;
HBox {
  paddingTop: 5;
  paddingBottom: 5;
  paddingLeft: 5;
  paddingRight: 5;
  dropShadowEnabled: true;
}
&lt;/mx:Style&gt;
</pre>
<p></span></p>
<p>Usually the <em>dropShadowEnabled: true</em> would be enough but in this case you may be surprised if you put the above style into an MXML file with an HBox in it. Drop shadows don&#8217;t work on HBox components without some more tweaking. They don&#8217;t work for VBox, FormItem, Canvas, Grid, and Tile either. But dropShadowEnabled works beautifully to create Flex drop shadows on a component like TextInput.</p>
<p>What sets TextInput apart? It has a border by default. That is the key. Put <em>borderStyle: solid</em> in our style sheet then all the sudden our HBox has a drop shadow. Unfortunately it also has a nice one pixel border as well. To fix that we can set the borderThickness to zero and you&#8217;re done.</p>
<p><span class="syntaxhighlighterContainer">
<pre class="brush: xml;">
&lt;mx:Style&gt;
HBox {
  paddingTop: 5;
  paddingBottom: 5;
  paddingLeft: 5;
  paddingRight: 5;
  dropShadowEnabled: true;
  borderThickness: 0;
  borderStyle: solid;
}
&lt;/mx:Style&gt;
</pre>
<p></span></p>
<h3>Quick Two Point Summary</h3>
<ul>
<li>Drop shadows will be hidden if the component doesn&#8217;t have a border.</li>
<li>The border can be zero pixels.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Webon</title>
		<link>http://andrewcurioso.com/2009/03/webon/</link>
		<comments>http://andrewcurioso.com/2009/03/webon/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 20:32:24 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=353</guid>
		<description><![CDATA[I worked for Lycos on the Webon from the initial planning all the way through several major released versions. The result, a clean and easy to use cloud-based web publishing product. The project is now the preferred page building tool for another Lycos property: Angelfire. My major contributions to the project include: Software architecture design [...]]]></description>
			<content:encoded><![CDATA[<p>I worked for <a href="http://www.lycos.com">Lycos</a> on the <a href="http://webon.angelfire.lycos.com/">Webon</a> from the initial planning all the way through several major released versions. The result, a clean and easy to use cloud-based web publishing product. The project is now the preferred page building tool for another Lycos property: <a href="http://angelfire.lycos.com">Angelfire</a>.</p>
<p><span id="more-353"></span></p>
<div style="width: 50%; margin-right: 50%; position: relative;">
My major contributions to the project include:</p>
<ul style="padding-bottom: 97px;">
<li>Software architecture design and development.</li>
<li>Supporting XML schema design (a super-set of XHTML).</li>
<li>A cutting edge web based rich-text editor in Javascript.</li>
<li>A cutting edge CSS and theme editor as well as easy dynamic theme switching and previewing.</li>
<li>Unified Javascript libraries including dynamic module loading.</li>
<li>OpenSocial implementation.</li>
<li>OpenID integration.</li>
<li>Lycos Analytics &#8212; a Google-like web analytics platform.</li>
<li>Organized foosball tournaments.</li>
<li>Significant contributions to media management, module resizing, and project planning.</li>
<li>Additional contributions to blogging module, premium accounts, and user profiles.</li>
</ul>
<div style="position: absolute; left: 100%; top: 0; width: 100%">
What other people are saying:</p>
<blockquote><p>
[Webon] is a simplified and clean way in which to make a multimedia site.<br />
<a href="http://mashable.com/2008/05/19/lycos-webo/" class="citation">Kristen Nicole &#8211; Mashable</a>
</p></blockquote>
<blockquote><p>
&#8230; a free site-building service that&#8217;s solid, simple, and very usable.<br />
<a href="http://news.cnet.com/8301-17939_109-9947933-2.html" class="citation">Rafe Needleman &#8211; CNET</a>
</p></blockquote>
<blockquote><p>
If you&#8217;re interested in starting up a simple web site with virtually no learning curve, Webon looks like a good choice.<br />
<a href="http://lifehacker.com/393777/webon-makes-building-a-web-site-easy" class="citation">Adam Pash &#8211; Lifehacker</a>
</p></blockquote>
<p>More coverage:<br />
<a href="http://www.killerstartups.com/Blogging-Widgets/webon-com-easy-website-creation-from-lycos">Killer Startups</a><br />
<a href="http://www.bizinformer.com/50226711/webon_free_web_site_construction.php">BizInformer</a>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/03/webon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
