<?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>Mike Conley&#039;s Blog &#187; web applications</title>
	<atom:link href="http://mikeconley.ca/blog/tag/web-applications/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikeconley.ca/blog</link>
	<description>The personal blog of a Toronto based software developer, musician, sound designer, and theatre enthusiast.</description>
	<lastBuildDate>Tue, 10 Jan 2012 13:58:35 +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>Mouseover / Mouseout on Nested Elements</title>
		<link>http://mikeconley.ca/blog/2009/02/19/mouseover-mouseout-on-nested-elements/</link>
		<comments>http://mikeconley.ca/blog/2009/02/19/mouseover-mouseout-on-nested-elements/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 03:15:14 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[event handling]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[mouseout]]></category>
		<category><![CDATA[mouseover]]></category>
		<category><![CDATA[nested]]></category>
		<category><![CDATA[nested divs]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=174</guid>
		<description><![CDATA[Did I mention I&#8217;m code-sprinting over the next three days?  Actually, next two days &#8211; I just finished my first day today. What&#8217;s code-sprinting?  It&#8217;s a trendy term for sitting down with your team, and plowing through code en masse, trying to get as much done as possible.  8 hour days, cookies, coffee, whiteboards, pizza, [...]]]></description>
			<content:encoded><![CDATA[<p>Did I mention I&#8217;m code-sprinting over the next three days?  Actually, next two days &#8211; I just finished my first day today.</p>
<p>What&#8217;s code-sprinting?  It&#8217;s a trendy term for sitting down with your team, and plowing through code en masse, trying to get as much done as possible.  8 hour days, cookies, coffee, whiteboards, pizza, crashes, bugs, tickets, fixes, etc.  We&#8217;re trying to cram 3 weeks of work into 3 days.  Cool.</p>
<p>In case you don&#8217;t remember, I&#8217;m working on a project called Checkmark (or OLM&#8230;still undecided on the name) &#8211; a tool for Professors/TAs to receive student code submissions, and to facilitate easy marking and annotating of the submitted code.</p>
<p>So here&#8217;s something I learned today while coding:</p>
<p>Say you have some nested DIV&#8217;s, and the parent DIV has a mouseout trigger.  Something like this:</p>
<pre>&lt;div id="parent" onMouseOut="alert('Mouseout triggered on parent');"&gt;
  &lt;div id="child_1"&gt;This is some child&lt;/div&gt;
  &lt;div id="child_2"&gt;This is another child&lt;/div&gt;
&lt;/div&gt;</pre>
<p>As you would expect, the mouseout event will get triggered if you move your mouse over the parent DIV, and then move the mouse back out again.</p>
<p><strong>But it also gets triggered when you move your mouse OVER any of the child DIV&#8217;s. </strong></p>
<p>Say what?  That&#8217;s right &#8211; even though you&#8217;re still inside the parent DIV, the mouseout event got triggered.  I found this out today when I was trying to code dropdown menus in Javascript/CSS using Prototype &#8211; I could get the dropdown menus to appear find when I clicked on the appropriate button, but they&#8217;d disappear again as soon as I put my mouse over any of the sub-elements of the DIV.</p>
<p>So how did I fix this?  I found <a href="http://images.code-head.com/code/javascript/fixOnMouseOuttest.html">this example code</a>, and adapted it for my purposes.  This code assumes that you&#8217;re using the Prototype Javascript library.</p>
<pre>$('some_dropdown').observe('mouseout',
  function(event) {
     //We could probably replace the following with Event.element(event), but oh well.
     var target = $('some_dropdown');
     var mouse_over_element;  //What the mouse is currently over...
     //So let's check to see what the mouse is now over, and assign it to mouse_over_element...
     if( event.toElement ) {
        mouse_over_element = event.toElement;
     }
     else if(event.relatedTarget) {
       mouse_over_element = event.relatedTarget;
     }
     //In the event that the mouse is over something outside the DOM (like an alert window)...
     if(mouse_over_element == null) {
        return;
     }
     //Now we just make sure that what the mouse is currently over is NOT a descendant of
     //the dropdown, and that the target is not the current mouse_over_element (I can't
     //remember which case this covers, but it's important)
     if(!mouse_over_element.descendantOf(target) &amp;&amp; target != mouse_over_element) {
        target.hide();
     }
   }
 );</pre>
<p>And it works.  Whew!  Just thought I&#8217;d share that little snippit.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/19/mouseover-mouseout-on-nested-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Injection Prevention in PHP &#8211; Tip 1</title>
		<link>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/</link>
		<comments>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 21:36:38 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=157</guid>
		<description><![CDATA[It&#8217;s amazing &#8211; I&#8217;ve been going around, Googling for anything with &#8220;index.php?id=&#8221;&#8230;and that&#8217;s really all it takes.  Now, granted, SQL Injection isn&#8217;t new, and a lot of the top hits have taken some steps to protect themselves, but if you go deep &#8211; like, Google search page 23 deep &#8211; you&#8217;ll find ones that break [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s amazing &#8211; I&#8217;ve been going around, Googling for anything with &#8220;index.php?id=&#8221;&#8230;and that&#8217;s really all it takes.  Now, granted, SQL Injection isn&#8217;t new, and a lot of the top hits have taken some steps to protect themselves, but if you go deep &#8211; like, Google search page 23 deep &#8211; you&#8217;ll find ones that break if you put a semi-colon after the id # &#8211; and if it breaks, it&#8217;s vulnerable.</p>
<p>So, here&#8217;s my first tip on preventing SQL Injection &#8211; when you&#8217;re asking for an ID number, make sure it&#8217;s a number, and nothing else.  Also consider using prepared statements &#8211; database wrappers like <a href="http://pear.php.net/package/MDB2">MDB2</a> for PHP make this easy.</p>
<p>Check this out &#8211; this might be how I would have done it 3 years ago:</p>
<pre>&lt;?php
  //Assume we're already connected to a MySQL database...
  $id = $_GET['id'];

  $result = mysql_query('SELECT * from pages where id='.$id);
  if (!$result) {
     die('Invalid query: ' . mysql_error());
  }
  ... //Code to print out my result to the page
?&gt;</pre>
<p>I&#8217;d do it this way now:</p>
<p><strong>Note:</strong> My use of MDB2 might be a little rusty &#8211; I haven&#8217;t tested this code, and I usually compose RowDataGateway objects with MDB2 to represent my data.  So pay more attention to the structure than the actual syntax.</p>
<pre>&lt;?php
  require 'View.php';
  require 'MDB2.php';  //An excellent DB layer from the PEAR libs

  //Code to set $mdb2 as our DB connection variable
  //See http://pear.php.net/package/MDB2 for details
  $id = $_GET['id'];

  try {
    if(!is_int($id)) {
      //ID wasn't an int, it's no good, let's bail
      throw new Exception('Could not recognize the id that you passed');
    }
    //ID was an int, let's see if we can find the record
    $sql = 'SELECT * from pages where id=:id";
    $statement = $mdb2-&gt;prepare($sql);
    $statement-&gt;bindParam('id', $id);
    $result = $statement-&gt;execute();
    if(PEAR::isError($result)) {
      //Uh oh - our result was an error on the PEAR library level
      throw new Exception('There was an error communicating with the database');
    }
    //Insert the database result into the view, render, and die.
    $content = new View('templates/page.tpl', array('page' =&gt; $result-&gt;fetchOne()));
    $content-&gt;render();
    die;
  }
  catch(Exception $e) {
    //We must have caught an exception - put this into our
    //error page template with the error message, render, die.
    $content = new View('templates/error.tpl', array('message' =&gt; $e-&gt;getMessage()));
    $content-&gt;render();
    die;
  }
?&gt;</pre>
<p>Yes, it&#8217;s quite a bit more code.  But I feel safer just looking at it.<br />
Did I miss anything on this?  Please post a comment if you  notice that I&#8217;ve left a gaping hole.  Learning is good.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing SQL Injection Attacks</title>
		<link>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/</link>
		<comments>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 18:48:04 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=125</guid>
		<description><![CDATA[Over the reading week, along with studying for various midterms and assignments, I&#8217;ve decided to brush up on preventing SQL Injection attacks in web applications. Pretty scary/awesome stuff out there on this stuff.  Here&#8217;s a great place to get some SQL Injection training, and here&#8217;s an excellent SQL Injection cheat sheet. I got hit with [...]]]></description>
			<content:encoded><![CDATA[<p>Over the reading week, along with studying for various midterms and assignments, I&#8217;ve decided to brush up on preventing SQL Injection attacks in web applications.</p>
<p>Pretty scary/awesome stuff out there on this stuff.  <a href="http://www.hackthissite.org" target="_self">Here&#8217;s a great place to get some SQL Injection training</a>, and <a href="http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/" target="_self">here&#8217;s an excellent SQL Injection cheat sheet</a>.</p>
<p>I got hit with a pretty bad SQL Injection attack last summer on an application I had written 3 years ago (before I had any clue that SQL Injection attacks were possible).</p>
<p>Here&#8217;s the take home message:  <strong>never trust user input.  Ever. </strong>If you&#8217;re expecting an int, make sure it&#8217;s an int.  <strong>Never insert user input directly into an SQL string.</strong> Use prepared statements instead, or stored procedures.</p>
<p>Luckily, I just did a quick survey of all of my running apps, and I seem to be OK in terms of SQL Injection.  Still, it&#8217;s a common attack vector &#8211; and the consequences of being lazy on user input can be pretty awful.</p>
<p><strong>Update: </strong> Want to see something awesome?  <a href="http://www.milw0rm.com/video/watch.php?id=92" target="_self">Check this out &#8211; a Debian box gets rooted through MySQL injection&#8230;killer soundtrack too.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

