<?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>bradym.net</title>
	<atom:link href="http://bradym.net/feed" rel="self" type="application/rss+xml" />
	<link>http://bradym.net</link>
	<description>Random thoughts of a Code Monkey</description>
	<lastBuildDate>Sun, 11 Oct 2009 22:39:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating iCalendar (ics) files with PHP</title>
		<link>http://bradym.net/php/creating-icalendar-ics-files-with-php</link>
		<comments>http://bradym.net/php/creating-icalendar-ics-files-with-php#comments</comments>
		<pubDate>Sat, 15 Aug 2009 08:00:59 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[iCalendar]]></category>
		<category><![CDATA[ics]]></category>

		<guid isPermaLink="false">http://bradym.net/php/creating-icalendar-ics-files-with-php</guid>
		<description><![CDATA[This post was originally written several years ago and included my own attempt at building a very simple ical creator in PHP. I&#8217;ve been meaning to update this blog with some better code and information for quite some time. I finally found what I consider to be a very good class for creating iCalendar files [...]]]></description>
			<content:encoded><![CDATA[<p>This post was originally written several years ago and included my own attempt at building a very simple ical creator in PHP. I&#8217;ve been meaning to update this blog with some better code and information for quite some time. I finally found what I consider to be a very good class for creating iCalendar files using PHP: <a href="http://www.kigkonsult.se/iCalcreator/index.php">iCalcreator</a>. Along with creating iCalendar files, iCalcreator can also <a href="http://www.kigkonsult.se/iCalcreator/docs/using.html#parse_merge">parse and merge iCalendar files</a>, and spit out a modified version. There are lots of <a href="http://www.kigkonsult.se/downloads/index.php?#iCalcreator">examples available for download</a> on their site, as well as supporting utilities.</p>
<p>The <a href="http://www.kigkonsult.se/iCalcreator/docs/using.html">iCalcreator documentation</a> is excellent. The examples are easy to follow, and they clearly document how to use their class. Unfortunately, the iCalendar specification is complicated enough that you&#8217;ll still need to read rfc2445 to really take advantage of all of the options available to you. Some good iCalendar reference sites include:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/ICalendar">iCalendar &#8211; Wikipedia</a></li>
<li><a href="http://www.kanzaki.com/docs/ical/">iCalendar Specification Excerpts</a></li>
<li><a href="http://rfc.net/rfc2445.html">Entire iCalendar Specification (rfc2445)</a></li>
</ul>
<p>Since I haven&#8217;t actually built anything using iCalcreator yet (other than some quick test scripts earlier today) I can&#8217;t really answer any questions about its usage. The good news is they have a <a href="http://sourceforge.net/forum/?group_id=174828">forum on sourceforge</a> for questions. I&#8217;d love to hear about your experiences using iCalcreator, so feel free to leave your comments below.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fphp%2Fcreating-icalendar-ics-files-with-php';
  addthis_title  = 'Creating+iCalendar+%28ics%29+files+with+PHP';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/php/creating-icalendar-ics-files-with-php/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Simple PHP Syntax Highlighting</title>
		<link>http://bradym.net/php/simple-php-syntax-highlighting</link>
		<comments>http://bradym.net/php/simple-php-syntax-highlighting#comments</comments>
		<pubDate>Mon, 20 Apr 2009 05:01:49 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=93</guid>
		<description><![CDATA[One benefit to working as part of a development team is that you can ask your fellow developers to look at your code and ask for help. Sending code back and forth over email can be frustrating and even counter-productive. IMO, the ideal way to share code is by simply sending a URL and letting [...]]]></description>
			<content:encoded><![CDATA[<p>One benefit to working as part of a development team is that you can ask your fellow developers to look at your code and ask for help. Sending code back and forth over email can be frustrating and even counter-productive. IMO, the ideal way to share code is by simply sending a URL and letting the other developer view it in their browser with syntax highlighting.  Here&#8217;s one way that does not require any external libraries and is very easy to setup:</p>
<h2>Add this line to .htaccess</h2>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteRule</span> ^(.*)\.phps$ viewsource.php?file=$1.php [QSA,L]</pre></div></div>

<p>This rule sends all requests for files ending in .phps to the viewsource.php file with the path as an argument.</p>
<h2>Put the below script in the document root of your development server</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This script should *NEVER* be used on a production server!</span>
<span style="color: #666666; font-style: italic;">// By default, it will only run on localhost. If you want to run this script on</span>
<span style="color: #666666; font-style: italic;">// a staging server add the IP address of that server to $allowed_servers.</span>
<span style="color: #000088;">$allowed_servers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set $base_dir to the root of your web directory.</span>
<span style="color: #000088;">$base_dir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Make sure this script is running on an allowed server.</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$allowed_servers</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Do not run this script in production!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Exit if no file was specified</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No file specified.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Ensure the requested file is inside $base_dir and that it exists</span>
<span style="color: #000088;">$real_path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base_dir</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$real_path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$base_dir</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$real_path</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Access denied or file not found.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$real_path</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
    .num_margin {
        text-align: right;
        margin-right: 6pt;
        padding-right: 6pt;
        border-right: 1px solid gray;
    }
    .num_margin a {
        color: gray;
        font-size: 13px;
        font-family: monospace;
    }
    body { margin: 0px; margin-left: 5px; }
    div { float: left; }
&lt;/style&gt;
&nbsp;
&lt;/head&gt;
&lt;body&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$lines_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$real_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$lines</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&lt;a href=\&amp;quot;#<span style="color: #006699; font-weight: bold;">$line</span>\&amp;quot; name=\&amp;quot;<span style="color: #006699; font-weight: bold;">$line</span>\&amp;quot;&gt;<span style="color: #006699; font-weight: bold;">$line</span>&lt;/a&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">highlight_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$real_path</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>num_margin<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$lines</span>&lt;/div&gt;&lt;div&gt;<span style="color: #006699; font-weight: bold;">$content</span>&lt;/div&gt;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Now when you visit a link like: http://localhost/info.phps it will show the source of the file.  </p>
<p><strong><em>Note:  This script should never be used in production!</em></strong></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fphp%2Fsimple-php-syntax-highlighting';
  addthis_title  = 'Simple+PHP+Syntax+Highlighting';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/php/simple-php-syntax-highlighting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setup Xdebug on OS X Leopard</title>
		<link>http://bradym.net/php/setup-xdebug-on-os-x</link>
		<comments>http://bradym.net/php/setup-xdebug-on-os-x#comments</comments>
		<pubDate>Thu, 26 Feb 2009 07:59:17 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=79</guid>
		<description><![CDATA[Note: If you&#8217;re using Leopard, the directions below are for you. If you&#8217;re using Snow Leopard, just follow the directions provided at xdebug.org.
Most of the blog posts I&#8217;ve seen about getting Xdebug working on OS X insist that you must use MAMP or XAMPP to do so. But since PHP and Apache come included with [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note:</strong> If you&#8217;re using Leopard, the directions below are for you. If you&#8217;re using Snow Leopard, just follow the directions provided at <a href="http://xdebug.org/docs/install">xdebug.org</a>.</p>
<p>Most of the blog posts I&#8217;ve seen about getting <a href="http://xdebug.org/">Xdebug</a> working on OS X insist that you must use <a href="http://www.mamp.info/">MAMP</a> or <a href="http://xampp.org">XAMPP</a> to do so. But since <a href="http://php.net">PHP</a> and <a href="http://httpd.apache.org">Apache</a> come included with OS X, it seems like overkill to use one of those packages. </p>
<p>Contrary to popular belief, it is possible to get Xdebug working with the OS X standard Apache/PHP installation. Here&#8217;s how I did it:</p>
<ol>
<li><a href="http://xdebug.org/download.php">Download Xdebug source</a></li>
<li>Extract the xdebug tarball</li>
<li>cd into the xdebug directory</li>
<li>Run: phpize</li>
<li>Run: MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=&#8221;-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp&#8221; CCFLAGS=&#8221;-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe&#8221; CXXFLAGS=&#8221;-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe&#8221; LDFLAGS=&#8221;-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load&#8221; ./configure &#8211;enable-xdebug
<li>Run: make</li>
<li>cp modules/xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20060613 (note: your path may be slightly different)</li>
<li>add the following line to php.ini: zend_extension=&#8221;/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so&#8221;</li>
<li>Run: sudo apachectl restart</li>
<li>Write a PHP page that calls &#8220;phpinfo();&#8221; Load it in a browser and look for the info on the xdebug module.  If you see it, you have been successful!</li>
</ol>
<p>This is simply a modified version of the README file that comes with the xdebug source. The most important tweak is step 5, which sets the correct flags for the resulting module to work with Apache as it is compiled in OS X.</p>
<p>Note: If you&#8217;re currently using another debugger, you will need to disable it before Xdebug will work. </p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fphp%2Fsetup-xdebug-on-os-x';
  addthis_title  = 'Setup+Xdebug+on+OS+X+Leopard';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/php/setup-xdebug-on-os-x/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geocoding with PHP</title>
		<link>http://bradym.net/php/geocoding-with-php</link>
		<comments>http://bradym.net/php/geocoding-with-php#comments</comments>
		<pubDate>Wed, 25 Feb 2009 07:35:03 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=65</guid>
		<description><![CDATA[In my last post I mentioned geocoding using the Yahoo Geocoding API, so I thought I&#8217;d post some code to do exactly that.
For the purposes of this example, assume that we have a very simple MySQL database table with this structure:

CREATE TABLE `addresses` &#40;
	`id` int&#40;11&#41; NOT NULL auto_increment,
	`street` varchar&#40;255&#41; default NULL,
	`city` varchar&#40;255&#41; default NULL,
	`state` varchar&#40;2&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://bradym.net/php/http_build_query-and-arg_separator_output">last post</a> I mentioned geocoding using the <a href="http://developer.yahoo.com/maps/rest/V1/geocode.html">Yahoo Geocoding API</a>, so I thought I&#8217;d post some code to do exactly that.</p>
<p>For the purposes of this example, assume that we have a very simple MySQL database table with this structure:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`addresses`</span> <span style="color: #FF00FF;">&#40;</span>
	<span style="color: #008000;">`id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">auto_increment</span><span style="color: #000033;">,</span>
	<span style="color: #008000;">`street`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #008000;">`city`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #008000;">`state`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #008000;">`zip`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">9</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #008000;">`lat`</span> <span style="color: #999900; font-weight: bold;">float</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #000033;">,</span><span style="color: #008080;">6</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #008000;">`lon`</span> <span style="color: #999900; font-weight: bold;">float</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #000033;">,</span><span style="color: #008080;">6</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`id`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>Here&#8217;s the script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Geocode addresses using the Yahoo Geocoding API</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Turning on track_errors stores the latest PHP error in $php_errormsg.</span>
<span style="color: #666666; font-style: italic;">// This allows for more elegant display of the error messages without having to</span>
<span style="color: #666666; font-style: italic;">// code a php error handler, which would be overkill for such a simple script.</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'track_errors'</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'database_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Setup variables to be used later</span>
<span style="color: #000088;">$geocode_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://local.yahooapis.com/MapsService/V1/geocode&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Enter your custom appid here</span>
<span style="color: #000088;">$appid</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">'sample_appid'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the addresses that have not been geocoded</span>
<span style="color: #000088;">$address_result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT id, street, city, state, zip FROM addresses WHERE lat IS NULL OR lon IS NULL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// If the MySQL query returned any rows, loop through them</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address_result</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address_result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// appid is required for each call to the yahoo geocode API</span>
        <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'appid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$appid</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// output can be either xml or php</span>
        <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'output'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'php'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Store the row id for updating the database and remove from $row array</span>
        <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Build the query string for sending the request to yahoo</span>
        <span style="color: #000088;">$query_string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Get latitute / longitude</span>
        <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$geocode_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">.</span><span style="color: #000088;">$query_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// If the call to the yahoo api failed, display an error message</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'ERROR: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$php_errormsg</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Get the results of the api call and update the database records</span>
            <span style="color: #000088;">$response_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$lat</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ResultSet'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Result'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Latitude'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$lon</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ResultSet'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Result'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Longitude'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$update_result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE addresses SET lat = '<span style="color: #006699; font-weight: bold;">$lat</span>', lon = <span style="color: #006699; font-weight: bold;">$lon</span> WHERE id = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// For each record, let the user know if the update was successful. If not, display the mysql error message generated.</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$update_result</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Added lattitude and longitude for <span style="color: #006699; font-weight: bold;">{$row['street']}</span> <span style="color: #006699; font-weight: bold;">{$row['city']}</span>, <span style="color: #006699; font-weight: bold;">{$row['state']}</span> <span style="color: #006699; font-weight: bold;">{$row['zip']}</span>.&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Unable to add lattitude and longitude for <span style="color: #006699; font-weight: bold;">{$row['street']}</span> <span style="color: #006699; font-weight: bold;">{$row['city']}</span>, <span style="color: #006699; font-weight: bold;">{$row['state']}</span> <span style="color: #006699; font-weight: bold;">{$row['zip']}</span>
                      MySQL Error: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Nothing to do.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The code is documented pretty well so I&#8217;ll just point out a couple things</p>
<ul>
<li>The Yahoo Geocoding API can return either XML or PHP serialized objects. I chose PHP serialized objects because it&#8217;s easier to deal with for what I&#8217;m trying to do.</li>
<li>http_build_query does not exist in PHP4. To use this code with PHP4 you could use the <a href="http://pear.php.net/package/PHP_Compat">PHP_COMPAT Pear Package</a> or the http_build_query function from the <a href="http://www.codeigniter.com">CodeIgniter</a> <a href="http://codeigniter.com/user_guide/helpers/compatibility_helper.html">Compatibility Helper</a>.</li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fphp%2Fgeocoding-with-php';
  addthis_title  = 'Geocoding+with+PHP';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/php/geocoding-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>http_build_query() and arg_separator.output</title>
		<link>http://bradym.net/php/http_build_query-and-arg_separator_output</link>
		<comments>http://bradym.net/php/http_build_query-and-arg_separator_output#comments</comments>
		<pubDate>Fri, 26 Sep 2008 06:40:41 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=33</guid>
		<description><![CDATA[The other day I was using http_build_query to generate URLs to use with the Yahoo Geocoding API and kept getting back a &#8220;400 Bad Request&#8221; error back from Yahoo. The URLs were being echo&#8217;ed and looked fine, I could copy the URL and paste it in the browser address bar and get the results I [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was using <a href="http://php.net/http_build_query">http_build_query</a> to generate URLs to use with the <a href="http://developer.yahoo.com/maps/rest/V1/geocode.html">Yahoo Geocoding API</a> and kept getting back a &#8220;400 Bad Request&#8221; error back from Yahoo. The URLs were being <a href="http://php.net/echo">echo&#8217;</a>ed and looked fine, I could copy the URL and paste it in the browser address bar and get the results I was looking for.</p>
<p>When I finally viewed the source I saw that the urls were being created with &amp;amp; as the separator for the variables in the query string instead of &amp;. That explained why the url looked fine when it wsa echo&#8217;ed but didn&#8217;t work when executed.</p>
<p>This is where <a href="http://php.net/manual/en/ini.core.php#ini.arg-separator.output">arg_separator.output</a> comes in. This setting in php.ini determines what character(s) are used when generating URLs using the built in PHP functions. So to get my code working, I just needed to change the value to just an &amp;:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'arg_separator.output'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I just wish it hadn&#8217;t taken me so long to figure that out!</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fphp%2Fhttp_build_query-and-arg_separator_output';
  addthis_title  = 'http_build_query%28%29+and+arg_separator.output';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/php/http_build_query-and-arg_separator_output/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Canonical redirect on IIS using PHP</title>
		<link>http://bradym.net/php/canonical-redirect-iis</link>
		<comments>http://bradym.net/php/canonical-redirect-iis#comments</comments>
		<pubDate>Thu, 04 Sep 2008 04:37:49 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=19</guid>
		<description><![CDATA[According to the seo experts of the world, it is good practice to force your website to always use the same domain. So, instead of having your site work at both www.example.com and example.com, choose one. Once you&#8217;ve chosen which form of your site to use, it&#8217;s time to setup 301 redirects to enforce that.
If [...]]]></description>
			<content:encoded><![CDATA[<p>According to the <a href="http://www.mattcutts.com/blog/seo-advice-url-canonicalization/">seo experts</a> of the world, it is good practice to force your website to always use the same domain. So, instead of having your site work at both www.example.com and example.com, choose one. Once you&#8217;ve chosen which form of your site to use, it&#8217;s time to setup 301 redirects to enforce that.</p>
<p>If you&#8217;re using Apache, it&#8217;s very easy, just add a quick mod_rewrite rule. You can <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#require-no-www-in-htaccess">remove the www</a> or <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#require-the-www-in-htaccess">force the use of www</a>. But since IIS doesn&#8217;t use .htaccess files, it takes a little more effort.</p>
<p><strong>Create a php.ini with the following content and upload it to your site root</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>php<span style="">&#93;</span></span>
cgi.force_redirect <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0</span>
<span style="color: #000099;">auto_prepend_file</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> C:\php_includes\canonical.php</span></pre></div></div>

<p>Keep in mind that you&#8217;ll need to change the file path to reflect the setup of your server.</p>
<p><strong>Upload canonical.php with the following contents</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #666666; font-style: italic;">// Any directory index filenames should go in here with a leading /</span>
<span style="color: #666666; font-style: italic;">// This is removed when doing the redirect in order to maintain consistency,</span>
<span style="color: #666666; font-style: italic;">// without this, when visiting example.com you would be redirected to www.example.com/index.htm</span>
<span style="color: #000088;">$index_files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/index.htm'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/index.html'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/index.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The rewrite only kicks in if the host does not begin with www. and the code is not running</span>
<span style="color: #666666; font-style: italic;">// on localhost. When developing a site I setup dev.example.com on my dev machine and use</span>
<span style="color: #666666; font-style: italic;">// the same code as is on the live server, so I don't want to be redirected if I'm</span>
<span style="color: #666666; font-style: italic;">// accessing the code locally.</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'www.'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'LOCAL_ADDR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$index_files</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 301 Moved Permanently'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">$url</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Notes:</p>
<ul>
<li>This method assumes that you don&#8217;t have access to modify the server settings, ie: shared windows hosting. If you are able to modify how IIS is setup I&#8217;m sure there&#8217;s a better way to do this.</li>
<li>When PHP is run as a cgi, you can overwrite the php.ini settings by putting a php.ini in the site root. So if your windows host is not running php as a cgi, this won’t work. I think that php is always run as a cgi on IIS, but I could be wrong.</li>
<li>This will only work if the site is using PHP – if you have a completely static site this won&#8217;t help you. In order to use this with a static site, you&#8217;d have to change the server settings to treat your html files as php files.</li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fphp%2Fcanonical-redirect-iis';
  addthis_title  = 'Canonical+redirect+on+IIS+using+PHP';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/php/canonical-redirect-iis/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing in multiple versions of IE</title>
		<link>http://bradym.net/windows/testing-in-multiple-versions-of-ie</link>
		<comments>http://bradym.net/windows/testing-in-multiple-versions-of-ie#comments</comments>
		<pubDate>Thu, 28 Aug 2008 05:02:40 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=15</guid>
		<description><![CDATA[One question that I get all the time is how to test a website in both IE6 and IE7 on the same computer. Here are some options:
Virtual Machine
Because the code for Internet Explorer is so tightly integrated into Windows, the only way to run the &#8220;pure / authentic&#8221; version of IE6 on the same machine [...]]]></description>
			<content:encoded><![CDATA[<p>One question that I get all the time is how to test a website in both IE6 and IE7 on the same computer. Here are some options:</p>
<h2>Virtual Machine</h2>
<p>Because the code for Internet Explorer is so tightly integrated into Windows, the only way to run the &#8220;pure / authentic&#8221; version of IE6 on the same machine as IE7 is by using a Virtual Machine. Microsoft has made this easy by providing a <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=21eabb90-958f-4b64-b5f1-73d0a413c8ef&amp;displaylang=en">Virtual PC image for this purpose</a>. Virtual PC is also available for <a href="http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx">free download</a>, so this is a great option. There are two downsides to this option, the VPC image is over 400MB in size, and the image periodically expires requiring a new download every 6 months or so.</p>
<p>If you have a copy of Windows XP sitting around you could use <a href="http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx">Virtual PC</a>, <a href="http://vmware.com/">VMWare</a>, <a href="http://virtualbox.org/">VirtualBox</a> or any other virtualization software to create your own non-expiring image for testing.</p>
<h2>IE6 Standalone</h2>
<p>The <a href="http://browsers.evolt.org/">Evolt Browser Archive</a> includes a <a href="http://browsers.evolt.org/download.php?/ie/32bit/standalone/ie6eolas_nt.zip">standalone version of IE6</a>. Simply download the zip archive, unzip and run iexplore.exe. Simplifiy your life by creating a shortcut in your start menu or on your desktop. This is my preferred method, mostly due to the simplicity, and has worked very well for me.</p>
<h2>Multiple IE</h2>
<p>Want to test more than just IE6? <a href="http://tredosoft.com/Multiple_IE">Multiple IE</a> installs IE3 &#8211; IE6 standalone versions. It&#8217;s been a long time since I&#8217;ve cared about how something looked in anything earlier than IE6, but if you have a reason to test a site on an earlier version of IE, this is a good way to go.</p>
<h2>IE7 Standalone</h2>
<p>The above options assume that you&#8217;ve already installed IE7. The makers of Multiple IE also have an installer for <a href="http://tredosoft.com/IE7_standalone">IE7 standalone</a> (but it&#8217;s not integrated into Multiple IE). The idea here is that ou would run IE6 natively, with IE7 in standalone mode. I&#8217;ve never sucessfully used this option, but others have found it useful.</p>
<h2>Gotchas</h2>
<p>Running a standalone version of Internet Explorer <em><strong>is not the same</strong></em> as running the native, built-into-windows version.</p>
<p>Due to IE&#8217;s reliance on DLLs and registrty settings, things can get messy in certain situations. Take a look at <a href="http://www.positioniseverything.net/articles/multiIE.html">Taming Your Multiple IE Standalones</a> for more information on these possible snags. In short, they recommend using Multiple IE, as the registry hacks and DLLs are all included.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fwindows%2Ftesting-in-multiple-versions-of-ie';
  addthis_title  = 'Testing+in+multiple+versions+of+IE';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/windows/testing-in-multiple-versions-of-ie/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging requests with MySQL</title>
		<link>http://bradym.net/mysql/logging-requests-with-mysql</link>
		<comments>http://bradym.net/mysql/logging-requests-with-mysql#comments</comments>
		<pubDate>Sat, 12 Jul 2008 22:49:33 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=13</guid>
		<description><![CDATA[One of my recent work projects was publishing a widget which others can add to their websites by copying some code and using it on their site. Similar to how YouTube makes it easy to embed their videos elsewhere.
Of course we want to know how and where this widget is being used so we can [...]]]></description>
			<content:encoded><![CDATA[<p>One of my recent work projects was publishing a widget which others can add to their websites by copying some code and using it on their site. Similar to how <a href="http://youtube.com">YouTube</a> makes it easy to embed their videos elsewhere.</p>
<p>Of course we want to know how and where this widget is being used so we can decide if it&#8217;s worth doing more widgets in the future, so we needed to include tracking. What we want to know is where the widget is being used, and how many times it is being displayed on those URLs.</p>
<p>The tracking table is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> widget_impressions
<span style="color: #FF00FF;">&#40;</span>
	id <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">auto_increment</span><span style="color: #000033;">,</span>
        referral_url <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
        counter <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
        date_created <span style="color: #999900; font-weight: bold;">date</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
        <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span>referral_url<span style="color: #000033;">,</span>date_created<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
        <span style="color: #FF9900; font-weight: bold;">UNIQUE</span> <span style="color: #990099; font-weight: bold;">KEY</span> id <span style="color: #FF00FF;">&#40;</span>id<span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>Technically, the id column is not needed since the primary key is a combination of the referral_url and the date_viewed field, but it can be handy in some situations.</p>
<p>When the widget is displayed, the following query is run:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> widget_impressions
	<span style="color: #990099; font-weight: bold;">SET</span>
		referral_url <span style="color: #CC0099;">=</span> <span style="color: #008000;">'http://example.com'</span><span style="color: #000033;">,</span>
		date_viewed <span style="color: #CC0099;">=</span> <span style="color: #000099;">now</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
		counter <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span>
	<span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #990099; font-weight: bold;">DUPLICATE KEY</span> <span style="color: #990099; font-weight: bold;">UPDATE</span>
		counter <span style="color: #CC0099;">=</span> counter <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span></pre></div></div>

<p>If this is the first visit from http://example.com for the day, a new record will be added to the table. If it&#8217;s not the first record for the day, the counter will be incremented by one. Using the date type for the date_viewed field means only the date is stored, not the time. If a datetime field were used, this method would not work the same way; we&#8217;d have separate entries in the table every time someone viewed the widget.</p>
<p>With this table structure it&#8217;s very easy to get stats. Say you want to know all of the pages where the widget is displayed and how many times it has been displayed on each:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> referral_url<span style="color: #000033;">,</span> <span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>counter<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">as</span> num_views
<span style="color: #990099; font-weight: bold;">FROM</span> widget_impressions
<span style="color: #990099; font-weight: bold;">GROUP BY</span> referral_url<span style="color: #000033;">;</span></pre></div></div>

<p>Want to know the 10 sites that are displaying your widget the most?</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> referral_url<span style="color: #000033;">,</span> <span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>counter<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">as</span> num_views
<span style="color: #990099; font-weight: bold;">FROM</span> widget_impressions
<span style="color: #990099; font-weight: bold;">GROUP BY</span> referral_url
<span style="color: #990099; font-weight: bold;">ORDER BY</span> num_views <span style="color: #990099; font-weight: bold;">DESC</span>
<span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">10</span><span style="color: #000033;">;</span></pre></div></div>

<p>References:</p>
<ul>
<li><a href="http://bradym.net/mysql/on-duplicate-key-update">MySQL &#8211; on duplicate key update</a></li>
<li><a href="http://http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html">Overview of Date and Time Types</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_now">now()</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fmysql%2Flogging-requests-with-mysql';
  addthis_title  = 'Logging+requests+with+MySQL';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/mysql/logging-requests-with-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; on duplicate key update</title>
		<link>http://bradym.net/mysql/on-duplicate-key-update</link>
		<comments>http://bradym.net/mysql/on-duplicate-key-update#comments</comments>
		<pubDate>Mon, 07 Jul 2008 01:57:00 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=12</guid>
		<description><![CDATA[If you&#8217;ve ever built an application that interacts with a database and allows users to edit data, or one that migrates data from one system to another you&#8217;ve probably written code like this:

// $id would have been set based on some other operation above.
// I'm setting it here for clarification.
$id = 1;
&#160;
$result = mysql_query&#40;&#34;SELECT id [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever built an application that interacts with a database and allows users to edit data, or one that migrates data from one system to another you&#8217;ve probably written code like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// $id would have been set based on some other operation above.</span>
<span style="color: #666666; font-style: italic;">// I'm setting it here for clarification.</span>
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT id FROM table_name WHERE id = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// Zero results, the record doesn't exist, add it.</span>
     <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO table_name (id,a,b) VALUES (<span style="color: #006699; font-weight: bold;">$id</span>,2,3)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// The record exists, update it.</span>
     <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE table_name SET a = 1, b = 2 WHERE id = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Well, thanks to the ON DUPLICATE KEY UPDATE option in MySQL this can be condensed to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO table_name SET id = <span style="color: #006699; font-weight: bold;">$id</span>, a = 2, b = 3
					 ON DUPLICATE KEY UPDATE
					 a = 2, c = 3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notes:</p>
<ul>
<li>You don&#8217;t have to update every field on update. If you only need one row updated if the row already exists, specify only that row in the UPDATE portion of the query.</li>
<li>I prefer the above syntax (using set and writing field = value for each field) but as shown in the <a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html">MySQL manual</a>, it works with the (field1,field2,field3) VALUES (value1,value2,value3) version as well.</li>
<li><em><strong>This method does not work perfectly in all situations! Be sure to test on your dev server before using in production!</strong></em></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fmysql%2Fon-duplicate-key-update';
  addthis_title  = 'MySQL+%26%238211%3B+on+duplicate+key+update';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/mysql/on-duplicate-key-update/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making the Windows Command Prompt Usable</title>
		<link>http://bradym.net/windows/making-the-windows-command-prompt-usable</link>
		<comments>http://bradym.net/windows/making-the-windows-command-prompt-usable#comments</comments>
		<pubDate>Tue, 29 Apr 2008 06:53:40 +0000</pubDate>
		<dc:creator>bradym</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://bradym.net/?p=11</guid>
		<description><![CDATA[If you&#8217;ve used an interactive shell on Linux or OS X you know what a good command prompt is like. To go from that to the command prompt in Windows XP is painful, since I&#8217;m stuck on Windows at work, I had to do something about the command prompt to make it more bearable.
Install Console
Console [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve used an interactive shell on Linux or OS X you know what a good command prompt is like. To go from that to the command prompt in Windows XP is painful, since I&#8217;m stuck on Windows at work, I had to do something about the command prompt to make it more bearable.</p>
<h2><strong>Install Console</strong></h2>
<p><a title="Console" href="http://sourceforge.net/projects/console">Console</a> is an <a href="http://www.opensource.org/">Open Source</a> command prompt window enhancement. If you&#8217;re familiar with <a href="http://konsole.kde.org/">Konsole</a> from <a href="http://kde.org">Kde</a>, Console has a similar feature set.</p>
<p>Console allows you much greater control over the display and setup of the command prompt including resizing the console, specifying background and font colors, specifying a startup directory, using tabs, etc.</p>
<p>There&#8217;s no installer with Console, just extract the zip file and run console.exe. I&#8217;ve created shortcuts in my taskbar and on the desktop for easy access. Once you&#8217;ve launched Consoe, be sure to spend some time playing around with the settings, that&#8217;s where all the power is!<strong><br />
</strong></p>
<h2><strong>Install Cygwin or GNUWin32</strong></h2>
<p>Now that we have a decent console, it&#8217;s time to get some *nix goodness! There are two great options for getting ports of *nix tools working on Windows: <a href="http://www.cygwin.com">Cygwin</a> and <a href="http://gnuwin32.sourceforge.net/">GnuWin32</a>.</p>
<p>Cygwin provides a more *nix like environment, as well as a larger number of tools overall. Cygwin includes a batch file to launch a command prompt with bash as the interpreter. With Cygwin you can also install an X server and run programs that require an X server, though if you&#8217;re trying to do that it&#8217;d be much easier to install <a href="http://www.virtualbox.org/">VirtualBox</a> or <a href="http://www.vmware.com/products/player/">VMWare Player</a> and run a virtual instance of your favorite *nix distro.</p>
<p>GnuWin provides Windows ports of many *nix tools, but does not try to imitate the *nix filesystem like Cygwin does. If you&#8217;re only looking for specific tools it may be easier to get them from GnuWin32.</p>
<p>I&#8217;m currently using Cygwin as it&#8217;s a standard at work.</p>
<h2>Using *nix Tools from the Windows Command Line</h2>
<p>Now that we have our command line and our *nix tools, all that&#8217;s left is to connect the two by adding the folder with the binaries to your Windows path. For Cygwin this is c:\cygwin\bin by default.</p>
<ol>
<li>Right click on &#8220;My Computer&#8221; on your desktop (or in windows explorer)</li>
<li>Select &#8220;Properties&#8221;</li>
<li>Click the &#8220;Advanced&#8221; tab</li>
<li>Click on &#8220;Environment Variables&#8221;</li>
<li>Look at the top list of variables,
<ul>
<li>If there is not a variable named &#8220;Path&#8221;
<ol>
<li>Click on &#8220;New&#8221;</li>
<li>Enter &#8220;Path&#8221; in the &#8220;Variable name&#8221; field</li>
<li>Enter &#8220;C:\cygwin\bin&#8221; in the &#8220;Variable value&#8221; field</li>
</ol>
</li>
<li>If there is a variable named &#8220;Path&#8221;
<ol>
<li>Click &#8220;Edit&#8221;</li>
<li>Click in the &#8220;Variable value&#8221; box and go to the end of the field</li>
<li>Add a semi-colon ( ; )</li>
<li>Enter &#8220;C:\cygwin\bin&#8221;</li>
</ol>
</li>
</ul>
</li>
<li>Click OK 3 times and you should be ready to go</li>
</ol>
<p>Open Console and enjoy your much improved windows command prompt experience!</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fbradym.net%2Fwindows%2Fmaking-the-windows-command-prompt-usable';
  addthis_title  = 'Making+the+Windows+Command+Prompt+Usable';
  addthis_pub    = 'mydarb';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://bradym.net/windows/making-the-windows-command-prompt-usable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
