<?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>Chris Monnat &#187; How-to</title>
	<atom:link href="http://www.christophermonnat.com/topics/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christophermonnat.com</link>
	<description>Programmer Extraordinaire</description>
	<lastBuildDate>Thu, 26 Aug 2010 14:21:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How-to Ensure a Secure Connection Using PHP</title>
		<link>http://www.christophermonnat.com/2009/05/how-to-ensure-a-secure-connection/</link>
		<comments>http://www.christophermonnat.com/2009/05/how-to-ensure-a-secure-connection/#comments</comments>
		<pubDate>Fri, 01 May 2009 10:00:04 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.christophermonnat.com/?p=636</guid>
		<description><![CDATA[Image via Wikipedia When submitting sensitive information over the web it&#8217;s important to ensure that the requested page is being accessed via an HTTPS encrypted connection. I&#8217;ve come across some forms that don&#8217;t check whether a secure connection has been made or not. In other words, you can delete the S from HTTP and instead [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 171px;">
<dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/Image:SympaticoSecurityManagerSafe.png"><img title="‎Sympatico Security Manager" src="http://upload.wikimedia.org/wikipedia/en/9/99/SympaticoSecurityManagerSafe.png" alt="‎Sympatico Security Manager" width="161" height="131"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://en.wikipedia.org/wiki/Image:SympaticoSecurityManagerSafe.png">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>When submitting sensitive information over the web it&#8217;s important to <strong>ensure</strong> that the requested page is being accessed via an HTTPS encrypted connection. I&#8217;ve come across some forms that don&#8217;t check whether a secure connection has been made or not. In other words, you can delete the S from HTTP and instead of redirecting the user back to the HTTPS connection the form is just displayed unsecured. This is a BIG NO NO&#8230; as a programmer you cannot rely on the visitor, or even other developers who would be linking to the form, to request a form securely. In this post I will review how you can ensure that your users are accessing certain pages using a secure connection.<br />
<span id="more-636"></span></p>
<h2>The Server Superglobal</h2>
<p>How can you tell if your user is requesting a certain page using a secure connection (HTTPS)? Enter the <a href="http://www.php.net/manual/en/reserved.variables.server.php">PHP server surperglobal</a>.</p>
<p>&#8220;<var class="varname">$_SERVER</var> is an array containing information    such as headers, paths, and script locations. The entries in this    array are created by the web server.&#8221;<br />
- PHP Manual (http://www.php.net)</p>
<p>There are 2 elements within this array that you can check that will tell you whether the user has made a secure request or not: <strong>https</strong> and <strong>server_port</strong>.</p>
<h2>Programmer Beware</h2>
<p>Something to keep in mind is that each web server will provide or not provide certain information in the $_SERVER array depending on their configuration. The PHP manual also points this out:</p>
<p>&#8220;There is no guarantee that    every web server will provide any of these; servers may omit some,    or provide others not listed here.&#8221;<br />
- PHP Manual (http://www.php.net)</p>
<p>So I guess that brings us back to the original question: how can you tell if your user is requesting a certain page using a secure connection (HTTPS)? Of the 2 elements mentioned above, server_port is part of the CGI 1.1 specification so the chances are good that element will be available in most servers. You can check for the availability of the https element if you wish but you should also include a check of the server_port as a fallback.</p>
<h2>The Code</h2>
<p>There is a good code example in the <a href="http://www.php.net/manual/en/reserved.variables.server.php#89306">comments of the PHP manual</a> of a function that checks whether or not the user has made a secure request:</p>
<pre class="brush: php">
&lt;?php
function isSSL(){

if($_SERVER[&#039;https&#039;] == 1) /* Apache */ {
return TRUE;
} elseif ($_SERVER[&#039;https&#039;] == &#039;on&#039;) /* IIS */ {
return TRUE;
} elseif ($_SERVER[&#039;SERVER_PORT&#039;] == 443) /* others */ {
return TRUE;
} else {
return FALSE; /* just using http */
}

}
?&gt;
</pre>
<p>This example function makes use of both the https and server_port elements of the superglobal array and also takes into account the different values that might be provided based on the web server. The only thing I will mention about using the server_port element is to make sure you know what port your server is using for HTTPS connections. I believe 443 is the standard, but ports can be changed so you just want to make sure you are checking the correct port for your server.</p>
<h2>What about CodeIgniter (CI)?</h2>
<p>If your programming using CI, you could certainly put the function above in a helper and call it whenever necessary. Or, a technique I&#8217;ve used successfully in the past, is to put the check in a custom library and auto load it. When you do it this way the connection is tested every time a page is loaded automatically without you having to make any additional function calls. And instead of returning TRUE or FALSE you can simply redirect the user to the requested page using HTTPS instead of HTTP which truly automates the process.</p>
<p>One thing that can trip you up when making secure connections using CI is the address you&#8217;ve entered on line 14 of application/config/config.php. If you enter just a static address starting with HTTP then HTTP will be used when calling any URL helper function like site_url() or anchor(). To avoid this issue,&nbsp; you can replace line 14 with the following code from the <a href="http://codeigniter.com/wiki/Automatic_configbase_url/">CI wiki</a>:</p>
<pre class="brush: php">

$config[&#039;base_url&#039;] = ((isset($_SERVER[&#039;HTTPS&#039;]) &amp;amp;&amp;amp; $_SERVER[&#039;HTTPS&#039;] == &quot;on&quot;) ? &quot;https&quot; : &quot;http&quot;);
$config[&#039;base_url&#039;] .= &quot;://&quot;.$_SERVER[&#039;HTTP_HOST&#039;];
$config[&#039;base_url&#039;] .= str_replace(basename($_SERVER[&#039;SCRIPT_NAME&#039;]),&quot;&quot;,$_SERVER[&#039;SCRIPT_NAME&#039;]); 
</pre>
<p>This code will automatically set the base_url config element so you don&#8217;t have to. This also comes in real handy when writing portable code that you want to distribute to other users or clients for installation on their own servers.</p>
<h2>That&#8217;s a wrap</h2>
<p>That does it for making sure your files are being accessed securely. If you have any questions or use a different technique for checking secure connections please share them by posting a comment.</p>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2008/09/customizing-domains-with-wildcard-dns/' rel='bookmark' title='Permanent Link: Customizing Domains With Wildcard DNS'>Customizing Domains With Wildcard DNS</a></li>
<li><a href='http://www.christophermonnat.com/2009/02/implementing-facebook-connect-part-3-accessing-data-from-facebook/' rel='bookmark' title='Permanent Link: Implementing Facebook Connect (Part 3) &#8211; Accessing Data from Facebook'>Implementing Facebook Connect (Part 3) &#8211; Accessing Data from Facebook</a></li>
<li><a href='http://www.christophermonnat.com/2008/08/generating-pdf-files-using-codeigniter/' rel='bookmark' title='Permanent Link: Generating PDF files using CodeIgniter'>Generating PDF files using CodeIgniter</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2009/05/how-to-ensure-a-secure-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing Facebook Connect (Part 3) &#8211; Accessing Data from Facebook</title>
		<link>http://www.christophermonnat.com/2009/02/implementing-facebook-connect-part-3-accessing-data-from-facebook/</link>
		<comments>http://www.christophermonnat.com/2009/02/implementing-facebook-connect-part-3-accessing-data-from-facebook/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 16:00:41 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.christophermonnat.com/?p=479</guid>
		<description><![CDATA[About a month ago I posted a continuation of my Implementing Facebook Connect series on how to establish a connection to Facebook. In this post I am going to look at using that connection we established to access user data and render it on a page. XFBML Once you&#8217;ve established your connection to Facebook you [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago I posted a continuation of my Implementing Facebook Connect series on how to <a href="http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-2-establishing-a-connection/">establish a connection</a> to Facebook. In this post I am going to look at using that connection we established to access user data and render it on a page.</p>
<p><span id="more-479"></span></p>
<h2><span class="mw-headline">XFBML</span></h2>
<p><span class="mw-headline">Once you&#8217;ve established your connection to Facebook you now have access to a wide array of information, but to display this information you need to get familiar with </span>Facebook Markup Language (FBML), an extension to HTML. The cool thing with FBML is that you can access a lot of information without a lot of code. All you need is the FBML tag in your HTML document and that&#8217;s that.</p>
<h2>Rendering XFBML</h2>
<p>In order to render XFBML tags on your page you first need to add the appropriate doctype and HTML attribute to your document.</p>
<p><strong>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Strict//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#8221;&gt; &lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221; xmlns:fb=&#8221;http://www.facebook.com/2008/fbml&#8221;&gt;</strong></p>
<p>The above mark-up is a standard doctype declaration. The only thing to note here is the XML namespace attributes added to the HTML tag. These are necessary in order to IE to render things appropriately so you don&#8217;t want to leave them out.</p>
<p>After you have the appropriate doctype declared you need to initialize the JavaScript Client Library from the Facebook site. This script basically contacts Facebook servers and tells them that you want to display FBML on the page in question and it&#8217;s up to Facebook to provide all the necessary tools to do so.</p>
<pre class="brush: javascript">&lt;script src=&quot;http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
<p>Finllay you need to send them your API key using the following script (which should be placed right after the above JavaScript include).</p>
<pre class="brush: javascript">&lt;script type=&quot;text/javascript&quot;&gt;
FB_RequireFeatures([&quot;XFBML&quot;], function(){
FB.Facebook.init(&quot;YOUR_API_KEY_HERE&quot;, &quot;&lt;relative path from root&gt;/xd_receiver.htm&quot;);
});
&lt;/script&gt;</pre>
<h2>The Tags</h2>
<p>OK, so now that we have the environment setup to recognize and render FBML we can review some of the tags and what they do.</p>
<h3>&lt;fb:login-button&gt;&lt;/fb:login-button&gt;</h3>
<p>The login-button tag should be familar from my last post. This tag renders a Facebook Connect log-in button on your site. When a user clicks the button they are presented with the Facebook log-in form in a pop-up window. When they log-in your application is added to their list of approved applications.</p>
<h3>&lt;fb:name uid=&#8221;user_id&#8221;&gt;</h3>
<p>The name tag does just what it&#8217;s mark-up would suggest, it displays the users name. This tag has one required attribute called uid where you need to provide a user id. You can also use this tag with Facebook Pages as well by passing the page id instead of the user id in the uid attribute. For more information about the name tag, visit the <a href="http://wiki.developers.facebook.com/index.php/Fb:name">Developers Wiki</a>.</p>
<h3>&lt;fb:pronoun uid=&#8221;user_id&#8221;&gt;</h3>
<p>The pronoun tag displays a pronoun for a specified user. Again, this tag has one required attribute uid for the user id. For more information about the pronoun tag, visit the <a href="http://wiki.developers.facebook.com/index.php/Fb:pronoun">Developers Wiki</a>.</p>
<h3>&lt;fb:profile-pic uid=&#8221;user_id&#8221;&gt;</h3>
<p>The profile-pic tag can display a users Facebook profile picture in a number of different ways. After providing a user id for the uid attribute you can also specify a size (like thumb, small, pic_square, etc.). For more information about the profile-pic tag, visit the <a href="http://wiki.developers.facebook.com/index.php/Fb:profile-pic">Developers Wiki</a>.</p>
<h3>&lt;fb:grouplink gid=&#8221;group_id&#8221;&gt;</h3>
<p>The grouplink tag gives you the ability to display group page links using FBML.  Simply provide the group id for the gid attribute and your all set. For more information about the grouplink tag, visit the <a href="http://wiki.developers.facebook.com/index.php/Fb:grouplink">Developers Wiki</a>.</p>
<h3>&lt;fb:eventlink eid=&#8221;event_id&#8221;&gt;</h3>
<p>The eventlink tag is similar to the grouplink tag except for events. Fed an event id for the eid attribute it will render a link to the specified events page within Facebook. For more information about the grouplink tag, visit the <a href="http://wiki.developers.facebook.com/index.php/Fb:eventlink">Developers Wiki</a>.</p>
<h3>&lt;fb:serverfbml&gt;</h3>
<p>The serverfbml tag is a very powerful tag that allows you to render FBML on Facebooks servers within an iFrame on your page. Using this tag you can interact with Facebook data through forms and such and it all takes place on Facebooks servers for security reasons. For more information about the grouplink tag, visit the <a href="http://wiki.developers.facebook.com/index.php/Fb:serverfbml">Developers Wiki</a>.</p>
<h2>Try it yourself!</h2>
<p>For additional information about the tags mentioned here and others I would recommend checking out the <a href="http://wiki.developers.facebook.com/index.php/XFBML">Facebook Developers Wiki</a>. You can try things out on your own, or Facebook provides a number of <a href="http://wiki.developers.facebook.com/index.php/Trying_Out_Facebook_Connect#Intermediate:_Using_the_Facebook_Demo_Applications">demo files</a> available for download which use the tags mentioned above and others to help you get a better idea of what&#8217;s possible.</p>
<p>There is one post left in this series and I promise it won&#8217;t take me a month to post it. In this post we looked at accessing information from Facebook; in the final post we will look at sending information back to Facebook so stay tuned!</p>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-2-establishing-a-connection/' rel='bookmark' title='Permanent Link: Implementing Facebook Connect (Part 2) &#8211; Establishing a Connection'>Implementing Facebook Connect (Part 2) &#8211; Establishing a Connection</a></li>
<li><a href='http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-1/' rel='bookmark' title='Permanent Link: Implementing Facebook Connect (Part 1) &#8211; What is Facebook Connect?'>Implementing Facebook Connect (Part 1) &#8211; What is Facebook Connect?</a></li>
<li><a href='http://www.christophermonnat.com/2009/05/facebook-connect-library-for-codeigniter/' rel='bookmark' title='Permanent Link: Facebook Connect Library for CodeIgniter'>Facebook Connect Library for CodeIgniter</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2009/02/implementing-facebook-connect-part-3-accessing-data-from-facebook/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Selling Campaign Monitor to Your Customers</title>
		<link>http://www.christophermonnat.com/2009/01/selling-campaign-monitor-to-your-customers/</link>
		<comments>http://www.christophermonnat.com/2009/01/selling-campaign-monitor-to-your-customers/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 11:00:27 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.christophermonnat.com/?p=438</guid>
		<description><![CDATA[I am a big fan of the e-mail marketing app Campaign Monitor (CM) as you can see in my recent post 10 Reasons Why Campaign Monitor Rocks. Shortly after writing that post I decided to try and introduce CM to my users and see if I can sell them on the program. I developed a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.christophermonnat.com/wp-content/uploads/2009/01/scoutmailer.gif"><img class="size-full wp-image-457 alignright" title="scoutmailer" src="http://www.christophermonnat.com/wp-content/uploads/2009/01/scoutmailer.gif" alt="scoutmailer" width="160" height="142"></a>I am a big fan of the e-mail marketing app <a href="http://www.campaignmonitor.com">Campaign Monitor</a> (CM) as you can see in my recent post <a href="http://www.christophermonnat.com/2009/01/10-reasons-why-campaign-monitor-rocks/">10 Reasons Why Campaign Monitor Rocks</a>. Shortly after writing that post I decided to try and introduce CM to my users and see if I can sell them on the program. I developed a promotional site, I rebranded CM to match my chosen color scheme and logo and have started marketing it to my users. In this post I will outline why I choose to resell CM, what I did to get everything up and running and what my plans are for the future.<br />
<span id="more-438"></span></p>
<h2>Introducing ScoutMailer</h2>
<p>At <a href="http://www.leftofcentercom.com">Left of Center Communications</a> (LOCC) my primary target market is the boy and girl scouting communities. My flagship product, <a href="http://www.badgetracker.com">BadgeTracker</a>, is designed specifically for scout camps and <a href="http://www.sign-up-sheet.com">Sign-Up-Sheet.com</a> was first developed to help my local scout troop. So when it came time for me to figure out how I was going to sell CM it didn&#8217;t take me long to decide I would target it to the scouting community and thus <a href="http://www.scoutmailer.com">ScoutMailer</a> was born.</p>
<p>I choose to resell CM because the deal is just too good to pass up. There are no monthly fees, annual licensing fees or recurring fees of any kind. The only real long term cost is management time which isn&#8217;t that much thanks to CMs intuitive interface. Also, this isn&#8217;t just some referral or affiliate program that pays 20% &#8211; 30%. You can charge your clients whatever you want for the product. CM will take care of all the financial stuff and send you your cut at the end of every month via Paypal.</p>
<p>At the beginning of every new project I typically sit down and come up with a task list of things that need to be done in order to bring a new product to market. When I thought about ScoutMailer there really was only 4 things to do:</p>
<ul>
<li>Design logo and promotional site for scoutmailer.com domain.</li>
<li>Write website content.</li>
<li>Customize CM interface with colors and logos.</li>
<li>Promote through existing add channels using BadgeTracker and Sign-Up-Sheet.com.</li>
</ul>
<p>I outsourced the design of the logo and website so the only thing I needed to invest in that task was money. Writing the promotional website content was reasonably simple after seeing what other companies had done. Customizing CMs interface with my colors and logo was a simple 10 minute thing. Finally, promotion and marketing has really just begun. But that was it&#8230; less than 4 tasks to bring a new product to market.</p>
<h2>The Promo Site</h2>
<p>The biggest part to reselling CM is developing your own promotional materials. This process is really the same with any product, whether your the developer or just the reseller. The good news with CM is that they have a lot of resources available in the form of <a href="http://www.campaignmonitor.com/resources/entry/1701/screenshots-and-materials-you-can-use-on-your-site/">screenshots</a> and <a href="http://www.campaignmonitor.com/resources/entry/1700/rebranding-campaign-monitor-as-your-own-product/">how-to&#8217;s</a> to help you along. I would also encourage you to take a look at the <a href="http://www.campaignmonitor.com/customers/">customers section</a> of their website to see what other companies have done.</p>
<p>After about 2 weeks and some back and forth between myself and the designer we came up with the ScoutMailer promotional site:</p>
<p style="text-align: center;"><a href="http://www.christophermonnat.com/wp-content/uploads/2009/01/scoutmailer-online-mailing-list-management-powered-by-scoutmailer_1232387305174.png"><img class="size-full wp-image-440 aligncenter" title="scoutmailer-online-mailing-list-management-powered-by-scoutmailer_1232387305174" src="http://www.christophermonnat.com/wp-content/uploads/2009/01/scoutmailer-online-mailing-list-management-powered-by-scoutmailer_1232387305174.png" alt="scoutmailer-online-mailing-list-management-powered-by-scoutmailer_1232387305174" width="500" height="506"></a></p>
<p style="text-align: left;">Most all CM promotional sites are pretty much the same. They have the same site structure and content, but I wanted to make mine stand out a bit. So, I added a resources section to my site controlled by WordPress. My intention is to eventually develop some tutorials and how-to articles specifically for my group of users. The thing to remember about the promo site is you need to speak to your specific users. Put the product in terms that they will understand.</p>
<h2 style="text-align: left;">Customizing the Interface</h2>
<p style="text-align: left;">The folks over at CM have written <a href="http://www.campaignmonitor.com/resources/entry/1700/rebranding-campaign-monitor-as-your-own-product/">a helpful article</a> to walk you through the process of rebranding their product to fit your needs. This was really the only &#8220;gotcha&#8221; moment in this whole process for me. They provide a set number of color schemes to choose from and that&#8217;s it. You can&#8217;t define your own colors. As a heads up, you might want to review those options before settling on a color scheme for your promo site/brand for CM so that your logo and site design goes with the interface. I had a bit of an issue with their shade of red but I think everything turned out OK.</p>
<h2 style="text-align: left;">Overcoming the Language Barrier</h2>
<p>One of the issues I knew I would have to address in the promo site, and will probably have to work through in support requests, is the e-mail marketing terminology. My particular target market isn&#8217;t interested in an e-mail marketing tool&#8230; they are more looking for a mailing list management solution and the two don&#8217;t necessarily mean the same thing to them. They want something that let&#8217;s them send plain text reminders from time to time and maybe the odd HTML newsletter every so often&#8230; but that&#8217;s it!</p>
<p>Another issue that I foresee moving forward is that my user base probably won&#8217;t understand that campaign = e-mail message. There is going to be a bit of a language barrier that I&#8217;m going to have to deal with so that they understand the process. It would be totally cool if CM allowed us to customize the terminology used in the app someday. But for now I&#8217;m relying on my promo site to steer users in the right direction. I&#8217;m also thinking about potentially developing a glossary and posting that in the resources section to help. But it&#8217;s something for you to keep in mind depending on what audience you plan on marketing CM to.</p>
<h2 style="text-align: left;">What&#8217;s next?</h2>
<p>ScoutMailer officially launched just this past Monday. Marketing and promotion is still getting underway but it will be interesting to see if I get any takers. Another opportunity for selling CM to existing customers is integrating your existing products with the CM API. I&#8217;m going to look into this later this year to see if theres any value there. Keep watch for a how-to post on that in the near future.</p>
<p>That&#8217;s my story&#8230; do you have one? If you have been reselling CM for a while or just started, let me know what your experience has been in the comments.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/76d20275-4bb2-419d-a9b0-9024744989e6/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=76d20275-4bb2-419d-a9b0-9024744989e6" alt="Reblog this post [with Zemanta]"></a></div>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2009/01/10-reasons-why-campaign-monitor-rocks/' rel='bookmark' title='Permanent Link: 10 Reasons Why Campaign Monitor Rocks'>10 Reasons Why Campaign Monitor Rocks</a></li>
<li><a href='http://www.christophermonnat.com/2009/07/scoutmailer-case-study/' rel='bookmark' title='Permanent Link: ScoutMailer Case Study'>ScoutMailer Case Study</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2009/01/selling-campaign-monitor-to-your-customers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementing Facebook Connect (Part 2) &#8211; Establishing a Connection</title>
		<link>http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-2-establishing-a-connection/</link>
		<comments>http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-2-establishing-a-connection/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 12:00:01 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.christophermonnat.com/?p=379</guid>
		<description><![CDATA[Two weeks ago I took a look at Facebook Connect (FC) summarizing what it is and why developers would want to integrate it with their own applications in part 1 of this series. Originally I had thought this would be a two post topic but as I have learned more about FC I think it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago I took a look at Facebook Connect (FC) summarizing what it is and why developers would want to integrate it with their own applications in <a href="http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-1/">part 1</a> of this series. Originally I had thought this would be a two post topic but as I have learned more about FC I think it&#8217;s going to take a few posts to get up and running successfully. So, in this post we&#8217;re going to get all the pre-requisites out of the way and establish a connection with Facebook from our own application. We will then look at how we can do things with that connection in subsequent posts. Ready or not&#8230; let&#8217;s get started!<br />
<span id="more-379"></span></p>
<h2>Getting Started</h2>
<p>In order to use FC with your own application you first need to set your application up within Facebook so you can get your hands on an API key. As is the case when working with any API your API key will be used throughout your FC integration code for authentication purposes.</p>
<p><strong>Step 1 &#8211; Add Facebook Developers to Your Applications</strong></p>
<p>The first thing you need to do in order to set your application up within Facebook is add the Facebook Developers Application to your approved applications list. To do this, visit <a href="http://www.facebook.com/developers/">http://www.facebook.com/developers/</a>. Once you have added the developers application to your authorized applications list you will have access to all the developer resources that Facebook has to offer as well as a discussion board for questions and issues.<strong></strong></p>
<p><strong>Step 2 &#8211; Setup Your Application</strong></p>
<p style="text-align: left;">Now that you have added the developers application to your authorized applications list you can now proceed with setting your application up.</p>
<p style="text-align: center;"><a href="http://www.christophermonnat.com/wp-content/uploads/2009/01/facebook-developers.png"><img class="size-full wp-image-391 aligncenter" title="facebook-developers" src="http://www.christophermonnat.com/wp-content/uploads/2009/01/facebook-developers.png" alt="facebook-developers" width="500" height="209" /></a></p>
<p style="text-align: left;">Navigate back to the Facebook Developers application by visiting <a href="http://www.facebook.com/developers/">http://www.facebook.com/developers/</a> and click the <strong>Set Up New Application</strong> button at the top right of the window.</p>
<p style="text-align: left;">Now comes the fun part&#8230; setting up an application in Facebook involves a mega-form full of options and other required pieces of information. The form is fairly self-explanitory so I won&#8217;t take the time to go through it all with you. The only thing I will point out is the <strong>Connect</strong> tab. This section of the form concerns all the FC settings as they relate to your application. The only thing you need to concern yourself with at this point is the Base Domain field. &#8220;Specifying a base domain allows you to make calls using the <a title="PHP" href="http://wiki.developers.facebook.com/index.php/PHP">PHP</a> and <a title="JavaScript Client Library" href="http://wiki.developers.facebook.com/index.php/JavaScript_Client_Library">JavaScript</a> client libraries as well as get and store session information for any subdomain of the base domain.&#8221; Enter all the necessary information about your application and click <strong>Save Changes</strong>.</p>
<p style="text-align: center;"><a href="http://www.christophermonnat.com/wp-content/uploads/2009/01/facebook-edit-sign-up-sheet.png"><img class="size-full wp-image-394 aligncenter" title="facebook-edit-sign-up-sheet" src="http://www.christophermonnat.com/wp-content/uploads/2009/01/facebook-edit-sign-up-sheet.png" alt="facebook-edit-sign-up-sheet" width="500" height="203" /></a></p>
<h2 style="text-align: left;">Establishing a Connection</h2>
<p>Now that we have our API keys we can put the files in place that will help us establish a connection between our application and Facebook. I am having problems displaying code in my blog posts so for this post I&#8217;m just going to refer you to the FC <a href="http://wiki.developers.facebook.com/index.php/Trying_Out_Facebook_Connect#Basic:_Getting_Your_Site_and_Facebook_Connect_Working_in_Minutes">getting started guide</a> for the actual code to use. If any of you have any recommendations for tools to use to display code in WordPress blog posts I would love to hear them.</p>
<p><strong>Step 1 &#8211; First the CCC File</strong></p>
<p>The first thing we want to do is create something called the <a href="http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel">cross-domain channel communication</a> (CCC) file. That&#8217;s an awfully big name for such a little file. Basically this file provides the Facebook JavaScript Client Library with what it needs in order to function properly.</p>
<p>Copy the code from the FC getting started guide located under #2 and paste it into a new file named <strong>xd_receiver.htm</strong>. This file needs to be placed in a directory that&#8217;s relative to the callback URL that you entered when setting up your application in the mega-form above. For those of you following along using CodeIgniter, you should be able to get away with placing this file in the root of your CI application. That&#8217;s where everything is really referenced from anyway regardless of the search engine friendly URLs.</p>
<p><strong>Step 2 &#8211; Now the Test File</strong></p>
<p>Now that we have the CCC file we can begin writing the file we are going to use to establish our connection. Since we are only testing things in this post we will just make a simple file that displays the Facebook log-in button and adds the application to the users approved applications list. Go ahead and create a new file named <strong>test.htm</strong> and then follow along with the getting started guide starting with #3 for the necessary markup. Again, for those CI users you can place this markup in a view file and load it using whatever template your program is using.</p>
<p>Before running the script you want to be sure to replace <strong>YOUR_API_KEY_HERE</strong> with your API key and <strong>&lt;path from web root&gt;</strong> with the appropriate path to the CCC file. Once you have done that you can upload the two files we&#8217;ve created and test.</p>
<h2>That&#8217;s it!</h2>
<p>When viewing your test file in a browser all you should see is a Connect button displayed. When you click the button you should see a pop-up window prompting you to either login to your Facebook account or give your application permission to access your profile like in the screen shot below:</p>
<p style="text-align: center;"><a href="http://www.christophermonnat.com/wp-content/uploads/2009/01/fctesting.jpg"><img class="size-full wp-image-395 aligncenter" title="fctesting" src="http://www.christophermonnat.com/wp-content/uploads/2009/01/fctesting.jpg" alt="fctesting" width="500" height="395" /></a></p>
<p style="text-align: left;">Once you either login or give your application permission you can now go back to your Facebook account and look at the list of your authorized applications and you should now see your own application in the list.</p>
<h2 style="text-align: left;">What&#8217;s next?</h2>
<p style="text-align: left;">We didn&#8217;t get into much of the real nitty gritty in this post but we did lay the ground work for what is to come. In the next post I will begin looking at how we can access information about our users from Facebook and how we can send data back. Stay tuned!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/407ca00b-3b52-4862-9121-70c0f91e6498/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=407ca00b-3b52-4862-9121-70c0f91e6498" alt="Reblog this post [with Zemanta]" /></a></div>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2009/02/implementing-facebook-connect-part-3-accessing-data-from-facebook/' rel='bookmark' title='Permanent Link: Implementing Facebook Connect (Part 3) &#8211; Accessing Data from Facebook'>Implementing Facebook Connect (Part 3) &#8211; Accessing Data from Facebook</a></li>
<li><a href='http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-1/' rel='bookmark' title='Permanent Link: Implementing Facebook Connect (Part 1) &#8211; What is Facebook Connect?'>Implementing Facebook Connect (Part 1) &#8211; What is Facebook Connect?</a></li>
<li><a href='http://www.christophermonnat.com/2009/05/facebook-connect-library-for-codeigniter/' rel='bookmark' title='Permanent Link: Facebook Connect Library for CodeIgniter'>Facebook Connect Library for CodeIgniter</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-2-establishing-a-connection/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Implementing Facebook Connect (Part 1) &#8211; What is Facebook Connect?</title>
		<link>http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-1/</link>
		<comments>http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-1/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 12:00:30 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.christophermonnat.com/?p=346</guid>
		<description><![CDATA[Image via CrunchBase I have been spending some time recently developing an online community which will hopefully be launched next quarter. One of the things I wanted to integrate is OpenID to try and lessen the burden of signing-up and logging-in. However, after doing some research I&#8217;m thinking that Facebook Connect might be the better [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img">
<div>
<dl class="wp-caption alignright" style="margin: 1em; float: right; display: block; width: 255px;">
<dt class="wp-caption-dt"><a href="http://www.crunchbase.com/company/facebook"><img title="Image representing Facebook as depicted in Cru..." src="http://www.crunchbase.com/assets/images/resized/0000/4561/4561v1-max-450x450.png" alt="Image representing Facebook as depicted in Cru..." width="245" height="100" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://www.crunchbase.com">CrunchBase</a></dd>
</dl>
</div>
</div>
<p>I have been spending some time recently developing an online community which will hopefully be launched next quarter. One of the things I wanted to integrate is <a class="zem_slink" title="OpenID" rel="wikipedia" href="http://en.wikipedia.org/wiki/OpenID">OpenID</a> to try and lessen the burden of signing-up and logging-in. However, after doing some research I&#8217;m thinking that <a href="http://developers.facebook.com/connect.php">Facebook</a><a href="http://developers.facebook.com/connect.php"> Connect</a> might be the better way to go. This is the first of at least 2 posts about implementing Facebook Connect with your own PHP application. To begin we will first look at what Facebook Connect is and does and the next post will get technical and look at how to integrate it with your next <a class="zem_slink" title="CodeIgniter" rel="homepage" href="http://www.codeigniter.com">CodeIgniter</a> or PHP application.<br />
<span id="more-346"></span></p>
<h2>What is Facebook Connect and how does it differ from OpenID?</h2>
<p>Facebook Connect (FC) allows users with Facebook accounts to log into your website/service using their Facebook log-in credentials. OpenID provides the same functionality except instead of using your Facebook credentials you use your OpenID credentials. The difference between the two is that FC brings a lot more, in terms of features and functionality, to the table for developers to work with than OpenID does. FC allows users to take their web based social identity with them from site to site.</p>
<p>The <a href="http://developers.facebook.com">Facebook Developers site</a> has a lot of useful information on FC and what you can do with it. Using FC, you can enable &#8220;&#8230;your users to seamlessly &#8220;connect&#8221; their Facebook account and information with your site, connect and find their friends who also use your site and share information and actions on your site with their friends on Facebook.&#8221; In a nutshell, when you integrate FC with your website or web based application you are allowing your users to interact with their Facebook account from within your app thereby adding value to your site right off the bat.</p>
<p>As I stated above, FC offers more than just authentication. If a user logs into your application using FC you have the ability to interact with that users Facebook profile, friends, Facebook Feed, requests and notifications (if they give your app permission). A nice example of FC functionality and features is a sample app Facebook staff developed as an example called <a href="http://www.somethingtoputhere.com/therunaround/">The Run Around</a>. This example shows how FC would be integrated with a typical web app. You can either create your account using The Run Around registration form and connect your Facebook account later on the settings screen. Or, you can just use your Facebook account to log-in and forgo the static registration all together.</p>
<p>When a user logs into The Run Around, and they have connected their account to their Facebook account, the app can now post updates to the users Facebook Feed and show them any friends of theirs that are also using the app. So now you can not only leverage a users Facebook log-in information but you can create an app that interacts with that users Facebook account which I think is totally cool. This opens the door for developers to create nice sites that compliment Facebook and vice verse.</p>
<p>Now that we have covered what Facebook Connect is the next post in this series will begin to look at how we go about using it in our own apps. Check out <a href="http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-2-establishing-a-connection/">part 2</a> to estalibsh your applications connection to Facebook.</p>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2009/02/implementing-facebook-connect-part-3-accessing-data-from-facebook/' rel='bookmark' title='Permanent Link: Implementing Facebook Connect (Part 3) &#8211; Accessing Data from Facebook'>Implementing Facebook Connect (Part 3) &#8211; Accessing Data from Facebook</a></li>
<li><a href='http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-2-establishing-a-connection/' rel='bookmark' title='Permanent Link: Implementing Facebook Connect (Part 2) &#8211; Establishing a Connection'>Implementing Facebook Connect (Part 2) &#8211; Establishing a Connection</a></li>
<li><a href='http://www.christophermonnat.com/2009/05/facebook-connect-library-for-codeigniter/' rel='bookmark' title='Permanent Link: Facebook Connect Library for CodeIgniter'>Facebook Connect Library for CodeIgniter</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2009/01/implementing-facebook-connect-part-1/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Customizing Domains With Wildcard DNS</title>
		<link>http://www.christophermonnat.com/2008/09/customizing-domains-with-wildcard-dns/</link>
		<comments>http://www.christophermonnat.com/2008/09/customizing-domains-with-wildcard-dns/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 13:00:45 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.christophermonnat.com/?p=109</guid>
		<description><![CDATA[It seems to be the &#8220;in&#8221; feature of most modern web apps today. Giving your users the ability to create a custom URL that they can use to access their account like http://chickenbbq.sign-up-sheet.com. From a feature stand point its nice because it&#8217;s another way users can customize your app to their specifications. From a developers [...]]]></description>
			<content:encoded><![CDATA[<p>It seems to be the &#8220;in&#8221; feature of most modern web apps today. Giving your users the ability to create a custom URL that they can use to access their account like http://chickenbbq.sign-up-sheet.com. From a feature stand point its nice because it&#8217;s another way users can customize your app to their specifications. From a developers perspective however it can be a bit challenging to implement if you don&#8217;t know what your doing.<br />
<span id="more-109"></span></p>
<p>When I was developing my first web app (version 1 of <a href="http://www.badgetracker.com">BadgeTracker</a>) I really wanted to implement this feature, but for the life of me I couldn&#8217;t figure out how to do it. I didn&#8217;t even really know what it was called so I had a hell of a time searching for information. I then built <a href="http://www.sign-up-sheet.com">Sign-Up-Sheet.com</a> and still had no idea how to accomplish the effect, but I really needed to because each sign-up-sheet needed to have it&#8217;s own address and a dynamic address would have been perfect. I don&#8217;t really recall how I finally figured out what I was looking for, but the answer to my prayers was <a href="http://en.wikipedia.org/wiki/Wildcard_DNS_record">Wildcard DNS</a>. In this post I will walk you through implementing Wildcard DNS with your next web app.</p>
<h2>Disclaimer</h2>
<p>Before I get started I just wanted to mention that I do not claim to be a networking person. I don&#8217;t enjoy networking or server administration or anything like that&#8230; I&#8217;m software not hardware <img src='http://www.christophermonnat.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . However, this was a topic that I personally struggled with when starting out and I wanted to pass along what I have found and done.</p>
<h2>What is wildcard DNS?</h2>
<p>Wildcard DNS is typically defined as: an address record you can place in the DNS for your domain that will send all subdomains (not otherwise declared in your DNS) to a specified IP address. The concept is simple once you figure it out. Adding a Wildcard DNS record to your existing host records looks something like this:</p>
<p><strong>*.christophermonnat.com A 10.5.128.1</strong></p>
<p>The astrisk in this case is the wildcard character. This A record directs all subdomain requests to the IP 10.5.128.1. So now all you have to do is place you web app at the same IP address and you will be well on your way.</p>
<h2>Do I need a dedicated IP?</h2>
<p>It depends on how your app works. With Sign-Up-Sheet I have one CodeIgniter installation running 2 parts of the site. There is the website/admin area where users can browse the features of the program or sign-in to administer their account. And there is the actual public sign-up-sheet&#8217;s themselves which need to be displayed when a user enters the specified sheets address into the browser window. Because my app has 2 parts but is using the same CI installation I decided to use a shared IP for Sign-Up-Sheet.</p>
<p>With BadgeTracker there is only one CI installation but it has nothing to do with the website. The website and application are 2 physically separate things so the easiest way to facilitate this architecture was to get a dedicated IP for the application and leave the website with a shared IP. All subdomains go to the dedicated IP while the WWW record points to the shared.</p>
<p>When asking yourself this question I guess the determining factor boils down to how many parts there are to your app and whether they all belong to a single CI installation or many separate ones.</p>
<h2>Wildcard DNS and CI</h2>
<p>As I mentioned above, with Sign-Up-Sheet I have one CI install that handles both the display of sign-up-sheets decided by the URL and the front-end website/admin area. Since I&#8217;m using a shared IP I chose to have CI handle the determination of what to display to the user and when.</p>
<p>When doing something like this, there are 2 files you need to be concerned with: <strong>config/config.php</strong> and <strong>config/routes.php</strong>. In config.php, the issue is the base_url variable. This needs to be set to the home of your app in order for CI to operate properly. The problem with our implementation however is that it may change depending on what the user is requesting. Sometimes it will be a subdomain and other times it will be straight WWW. One way to account for this is to generate the base_url setting dynamically.</p>
<p>[code]<br />
$config['base_url'] = ((isset($_SERVER['HTTPS']) &#038;&#038; $_SERVER['HTTPS'] == "on") ? "https" : "http");<br />
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];<br />
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);<br />
[/code]</p>
<p>The above example is from the <a href="http://codeigniter.com/wiki/Automatic_configbase_url/">CI Wiki</a>. By placing this code in your config.php file, the base_url will be dynamically generated based on what is being requested thereby solving that problem. The other file we need to be concerned with is routes.php. The issue here is that we want to serve the user with a different default controller if they are visiting the site using a subdomain vs. just WWW. We can accomplish this with the following code:</p>
<p>[code]<br />
if(preg_match("/^([a-zA-Z0-9\-_]+)\.([a-zA-Z0-9\-_]+)\.([a-zA-Z]{2,5})$/",$_SERVER["SERVER_NAME"],$matches))<br />
{<br />
  list($subdomain,$domain,$tld) = $matches;<br />
}</p>
<p>if($domain == 'www'):<br />
	$route['default_controller'] = "main";<br />
else:<br />
	$route['default_controller'] = "signup";<br />
endif;<br />
[/code]</p>
<p>The above code looks at the URL and gets just the subdomain portion. We then look at the subdomain and determine if its WWW or something else. From there we decide which default controller to set for the application. Once placed in your routes.php file this accomplishes our goal nicely. Now that we are pointing our users to the correct controller we can refer to our database to find the records associated with the requested subdomain and proceed from there.</p>
<h2>Conclusion</h2>
<p>Wildcard DNS is available with most popular DNS providers like <a href="http://www.enom.com">Enom, Inc.</a> and <a href="http://www.godaddy.com">GoDaddy</a> and is also available with popular control panels like Plesk. If your not sure if your provider offers Wildcard DNS you should ask because there are some out there that don&#8217;t. Something I did want to mention about using Wildcard DNS is that it&#8217;s not necessarily the answer to all of your problems and should be implemented after careful consideration. The makers of <a href="http://www.wufoo.com">Wufoo</a>, a popular app that makes hosted web forms, wrote <a href="http://particletree.com/notebook/subdomains-development-sucks/">a post</a> a while ago about the issues they experienced while working with this kind of setup. It&#8217;s a must read before adopting this concept for your own apps.</p>
<p>Well, there you have it Wildcard DNS demystified. If you have any questions or if you are a networking/DNS genius and you see something I have gotten terribly wrong please post a comment and let me know.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/25d3cf69-5471-453f-8e85-68fd98e7ad97/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=25d3cf69-5471-453f-8e85-68fd98e7ad97" alt="Reblog this post [with Zemanta]"></a></div>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2009/05/how-to-ensure-a-secure-connection/' rel='bookmark' title='Permanent Link: How-to Ensure a Secure Connection Using PHP'>How-to Ensure a Secure Connection Using PHP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2008/09/customizing-domains-with-wildcard-dns/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to use reCAPTCHA with CI</title>
		<link>http://www.christophermonnat.com/2008/09/how-to-use-recaptcha-with-ci/</link>
		<comments>http://www.christophermonnat.com/2008/09/how-to-use-recaptcha-with-ci/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 16:46:12 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.christophermonnat.com/?p=160</guid>
		<description><![CDATA[Image by mathowie via Flickr SPAM&#8230; a nasty little four letter word. Could mean tasty meat in a can or could mean junk e-mails and form submissions clogging your server and taking up space in your inbox. We are all familiar with it and are engaged in a constant battle to stop it. In this [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; float: right; display: block;"><a href="http://www.flickr.com/photos/12037949644@N01/2366107675"><img style="display: block;" src="http://farm4.static.flickr.com/3095/2366107675_9905c51fe7_m.jpg" alt="ReCAPTCHA's quality is going down"></a><span class="zemanta-img-attribution">Image by <a href="http://www.flickr.com/photos/12037949644@N01/2366107675">mathowie</a> via Flickr </span></div>
<p>SPAM&#8230; a nasty little four letter word. Could mean tasty meat in a can or could mean junk e-mails and form submissions clogging your server and taking up space in your inbox. We are all familiar with it and are engaged in a constant battle to stop it. In this tutorial I&#8217;m going to show you how to implement a popular 3rd party <a href="http://en.wikipedia.org/wiki/CAPTCHA" title="CAPTCHA" rel="wikipedia" class="zem_slink">CAPTCHA</a> service with your CodeIgniter application.</p>
<p><span id="more-160"></span>The commonly accepted approach of handling form SPAM is by using a CAPTCHA control on your forms. The good news is that CodeIgniter comes with it&#8217;s own built in CAPTCHA functionality included <a href="http://codeigniter.com/user_guide/general/plugins.html">in the form of a plug-in</a>. I&#8217;ve used their plug-in before and it works well. It takes a little bit to get it setup and working properly and requires it&#8217;s own database table but it gets the job done. </p>
<p>There is, however, another CAPTCHA tool which I have been using a lot lately called <a href="http://www.recaptcha.org">reCAPTCHA</a> and I like it better. reCAPTCHA is a free hosted CAPTCHA service provided by Carnegie Mellon University and serving over 60 million CAPTCHAs a day. This service allows you to integrate a CAPTCHA control on your site quickly and easily without any database modifications or a lot of coding. Below are step-by-step instructions for integrating reCAPTCHA in your CI app.</p>
<h2>Step 1 &#8211; Create a reCAPTCHA account</h2>
<p>Before you can start working with reCAPTCHA you will first need to visit their website and <a href="https://admin.recaptcha.net/accounts/signup/">create an account</a>. Once you have filled out the form you will be logged in and prompted to enter your first site. Each site you wish to protect with reCAPTCHA needs to be entered in your account. This is because each site will get it&#8217;s own unique private and public keys which you will need to interact with the reCAPTCHA API. So, enter your domain name and click <strong>Create Key</strong>.</p>
<p>Once you have entered your domain you will now be presented with your public and private key. Take a minute to copy and paste those two long strings into a text document for later use. Be sure to keep track of which is which or else things won&#8217;t work properly.</p>
<h2>Step 2 &#8211; Download the reCAPTCHA PHP library</h2>
<p>Now that you have your keys, you will want to <a href="http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest">download</a> the PHP library they provide for interacting with the reCAPTCHA API. The archive you download will contain two example files and a code file called <strong>recaptchalib.php</strong>. Once you have the archive, unzip it and move the recaptchalib.php file into your applications helpers folder.</p>
<h4>Why a helper and not a library?</h4>
<p>We could certainly turn what they provided us into a library, but that would involve changing some of the code they provided since they are not providing a class. The recaptchalib.php contains a number of functions which are meant to help while interacting with the API. Therefore, it fits the helper definition nicely.</p>
<h2>Step 3 &#8211; Use the library in your project</h2>
<p>Now that we have the code we can use it in our application. The first thing we need to do is display the CAPTCHA control on the form your trying to protect. So, first load the helper:</p>
<pre class="brush: php">
$this-&gt;load-&gt;helper(&#039;recaptchalib&#039;);
</pre>
<p>Now that we have access to the helper functions, we can use the <strong>recaptcha_get_html()</strong> function.</p>
<pre class="brush: php">
&lt;?php echo recaptcha_get_html($public_key); ?&gt;
</pre>
<p>You will want to place this function in your view where you want to display the form control. This function takes only one argument: the public key you received earlier when you added your site to your reCAPTCHA account. You can either add both the public and private keys as class variables to your current controller. Or, my preference is to add the public and private keys to a custom config file that I autoload throughout my entire app. That way I can use the control anyplace in my site without duplicating my keys.</p>
<p>Now that we have the control displaying on our form we need to add code to handle the validation.</p>
<pre class="brush: php">
&lt;?php

// Validate the captcha submission.
function val_recaptcha($string)
{
	$resp = recaptcha_check_answer($this-&gt;config-&gt;item(&#039;recap_private&#039;),
									$_SERVER[&quot;REMOTE_ADDR&quot;],
									$this-&gt;input-&gt;post(&quot;recaptcha_challenge_field&quot;),
									$this-&gt;input-&gt;post(&quot;recaptcha_response_field&quot;));

	if(!$resp-&gt;is_valid) {
		$this-&gt;validation-&gt;set_message(&#039;val_recaptcha&#039;,&#039;Your answer for the security question was incorrect, please try again.&#039;);
		return FALSE;
	}
	else {
		return TRUE;
	}
}

function process_form()
{
	$this-&gt;load-&gt;library(&#039;validation&#039;);
	$this-&gt;load-&gt;helper(&#039;recaptcha_helper&#039;);

	$this-&gt;validation-&gt;set_error_delimiters(&#039;&lt;li&gt;&#039;, &#039;&lt;/li&gt;&#039;);

	// Validation rules.
	$rules[&#039;recaptcha_challenge_field&#039;] = &#039;required|callback_val_recaptcha&#039;;
	$this-&gt;validation-&gt;set_rules($rules);

	// Validation field names (for display in error messages).
	$fields[&#039;recaptcha_challenge_field&#039;] = &#039;Security Question&#039;;
	$this-&gt;validation-&gt;set_fields($fields);

	if($this-&gt;validation-&gt;run() == FALSE) {
		// display errors
	}
	else {
		// process submission
	}
}

?&gt;
</pre>
<p>In the above code we are using CI&#8217;s built in validation library to validate the CAPTCHA. You can of course add any additional rules or fields that are needed. I&#8217;ve created a custom validation function called <strong>val_recaptcha()</strong> which is called via a callback within the validation rules on the recaptcha_challenge_field field (which is created when we used the <strong>recaptcha_get_html()</strong> function above). This validation function uses the <strong>recaptcha_check_answer()</strong> function from the reCAPTCHA helper to check whether what the user submitted is correct or not.</p>
<p>And that&#8217;s really all there is to it. You are now using the same CAPTCHA protection as <a href="http://www.facebook.com/r.php?r=200">Facebook</a> and many other sites throughout the web. </p>
<h2>Wait&#8230; it&#8217;s RED! Can I make it look better?</h2>
<p>Absolutely, the reCAPTCHA website has detailed <a href="http://recaptcha.net/apidocs/captcha/client.html#customization">instructions</a> for how to alter the look and feel of the reCAPTCHA form control. There are a number of pre-set themes which you can choose from or you can create your own.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/5a8d6c8d-f133-484b-8284-17f574a68ffd/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=5a8d6c8d-f133-484b-8284-17f574a68ffd" alt="Reblog this post [with Zemanta]"></a></div>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2008/08/generating-pdf-files-using-codeigniter/' rel='bookmark' title='Permanent Link: Generating PDF files using CodeIgniter'>Generating PDF files using CodeIgniter</a></li>
<li><a href='http://www.christophermonnat.com/2009/05/how-to-ensure-a-secure-connection/' rel='bookmark' title='Permanent Link: How-to Ensure a Secure Connection Using PHP'>How-to Ensure a Secure Connection Using PHP</a></li>
<li><a href='http://www.christophermonnat.com/2009/05/building-applications-using-codeigniter-part-3-helpers/' rel='bookmark' title='Permanent Link: Building Applications using CodeIgniter (Part 3) &#8211; Helpers'>Building Applications using CodeIgniter (Part 3) &#8211; Helpers</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2008/09/how-to-use-recaptcha-with-ci/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Generating PDF files using CodeIgniter</title>
		<link>http://www.christophermonnat.com/2008/08/generating-pdf-files-using-codeigniter/</link>
		<comments>http://www.christophermonnat.com/2008/08/generating-pdf-files-using-codeigniter/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 13:00:18 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://dev.christophermonnat.com/?p=5</guid>
		<description><![CDATA[PDF files rock! Some of the programs used to view them could use some work, but the file format itself is real handy. As a programmer I have found PDF&#8217;s to be most helpful when generating reports that need to be printable. I know we are all supposed to be doing our part to make [...]]]></description>
			<content:encoded><![CDATA[<p>PDF files rock! Some of the programs used to view them could use some work, but the file format itself is real handy. As a programmer I have found PDF&#8217;s to be most helpful when generating reports that need to be printable. I know we are all supposed to be doing our part to make our offices &#8220;greener&#8221; and use less resources like paper. But some things just need to be printed (especially when your talking about the financial and legal industries).</p>
<p>When generating reports in PDF format you suddenly have a lot more control over layout and design than  you do with plain old HTML and CSS (although much progress is being made with print style sheets). You can create some really nice reports on the fly that your users can view, save for later or e-mail to their co-workers for review. In this post I will show you how I generate PDF reports using <a href="http://codeigniter.com" target="_blank">CodeIgniter</a>.</p>
<p><span id="more-5"></span></p>
<h2>Quick Note</h2>
<p>There are a number of PHP libraries out there for generating PDF files (like <a href="http://www.fpdf.org/">FPDF</a>, <a href="http://www.stillhq.com/opensource.html">Panda</a> and <a href="http://www.digitaljunkies.ca/dompdf/">dompdf</a>) but the best one I have come across is the <a href="http://www.ros.co.nz/pdf/">R&amp;OS pdf class</a>. I was first introduced to it from the <a href="http://www.sitepoint.com/books/phpant1/?SID=beb1c45753ae71830305e53194bf4faf">PHP Anthology</a> first edition by Harry Fuecks. I have tried other PDF libraries (some PHP 5 specific and some not) and none of them have been able to provide me with the same control or ease of use that the R&amp;OS class has which is why I&#8217;m using it for this tutorial.</p>
<h2>Getting Started</h2>
<p>Before we start, lets get everyone to the same place so you can follow along as we go. I&#8217;ve prepared a .zip file containing everything you&#8217;ll need to follow along. The archive includes CI 1.6.3 along with all the code and libraries we will discuss in this tutorial. Simply <a href="http://www.christophermonnat.com/wp-content/uploads/2008/07/pdf_tutorial.zip">download the archive</a>, unzip it on your web server and follow along.</p>
<p>I have done all the work of downloading the code library and putting the files in their right place for you, but I wanted to mention where things were for the detail oriented among you. There are 2 files that are necessary in order to use the R&amp;OS library: <strong>class.ezpdf.php</strong> and <strong>class.pdf.php</strong>. Those two files have been placed in the application/library folder. R&amp;OS also requires some font files in order to function and they have been placed at the root of the .zip file in a folder called <strong>fonts</strong>.</p>
<p>You do have to make a minor modification to the <strong>class.ezpdf.php</strong> file so that it will work properly within CI. First I renamed the file to <strong>cezpdf.php</strong>, which makes it easier to load using the CI loader. Then you have to modify the include statement on line 3 to:</p>
<pre class="brush: php">

include_once(APPPATH . &#039;libraries/class.pdf.php&#039;);
</pre>
<p>This will keep PHP from saying that it can&#8217;t find included file. Once those modifications are made the R&amp;OS class is ready to use with CI.</p>
<p>In the archive, I have also made a controller called<strong> tutorial.php</strong> and a helper called <strong>pdf_helper</strong>.<strong>php</strong> both in their respective directories. With the background info. out of the way, lets get our hands dirty with a real simple example.</p>
<h2>Hello World</h2>
<pre class="brush: php">

function hello_world()
{
$this-&gt;load-&gt;library(&#039;cezpdf&#039;);

$this-&gt;cezpdf-&gt;ezText(&#039;Hello World&#039;, 12, array(&#039;justification&#039; =&gt; &#039;center&#039;));
$this-&gt;cezpdf-&gt;ezSetDy(-10);

$content = &#039;The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.
Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.&#039;;

$this-&gt;cezpdf-&gt;ezText($content, 10);

$this-&gt;cezpdf-&gt;ezStream();
}
</pre>
<p>The above code produces a PDF file <a href="http://www.christophermonnat.com/wp-content/uploads/2008/07/hello_world.pdf">like this</a>.</p>
<p>In the above, first thing we do is load the R&amp;OS library for use. Next we use the <strong>ezText()</strong> function to create a title for our document. This function takes the text it will display as the first argument, the size of that text and an optional array of additional configuration options. In this instance we pass along a justification option of center. That will center our title at the top of our document.</p>
<p>After the title we insert some extra white space using the <strong>ezSetDy()</strong> function. After the whites pace we put the rest of the content for the document in a variable called $content and add it to our document using the <strong>ezText()</strong> function again. Finally, we create our document using the <strong>ezStream()</strong> function which actually creates the document and sends it to the users which prompts them to view/download the generated PDF document.</p>
<h2>Handling Tabular Data</h2>
<p>When your dealing with business reports the odds are good that you will need to generate reports with tables to display tabular data. From my experience with other PDF libraries, this is not an easy task. But with the R&amp;OS library it&#8217;s about as hard as creating an array.</p>
<pre class="brush: php">

function tables()
{
$this-&gt;load-&gt;library(&#039;cezpdf&#039;);

$db_data[] = array(&#039;name&#039; =&gt; &#039;Jon Doe&#039;, &#039;phone&#039; =&gt; &#039;111-222-3333&#039;, &#039;email&#039; =&gt; &#039;jdoe@someplace.com&#039;);
$db_data[] = array(&#039;name&#039; =&gt; &#039;Jane Doe&#039;, &#039;phone&#039; =&gt; &#039;222-333-4444&#039;, &#039;email&#039; =&gt; &#039;jane.doe@something.com&#039;);
$db_data[] = array(&#039;name&#039; =&gt; &#039;Jon Smith&#039;, &#039;phone&#039; =&gt; &#039;333-444-5555&#039;, &#039;email&#039; =&gt; &#039;jsmith@someplacepsecial.com&#039;);

$col_names = array(
&#039;name&#039; =&gt; &#039;Name&#039;,
&#039;phone&#039; =&gt; &#039;Phone Number&#039;,
&#039;email&#039; =&gt; &#039;E-mail Address&#039;
);

$this-&gt;cezpdf-&gt;ezTable($table_data, $col_names, &#039;Contact List&#039;, array(&#039;width&#039;=&gt;550));
$this-&gt;cezpdf-&gt;ezStream();
}
</pre>
<p>The above code should produce a PDF file <a href="http://www.christophermonnat.com/wp-content/uploads/2008/07/tables.pdf">like this</a>.</p>
<p>In the above code I create an array of data called $db_data. I put this together so that it imitates a typical database result set because that&#8217;s usually where you will be getting your data from. Below my data array I have created a $col_names array that associates the data elements in the $db_data array with a column title for the table. This is where the R&amp;OS gets the title to display at the top of each table column. Once I have the data and column titles I create the table by calling the <strong>ezTable()</strong> function. This function takes the data array, an associative array for column names, the title for the table and an optional array of configuration options. There are a number of options that can be configured through that last optional array, but I&#8217;m not going to go into them in this tutorial.</p>
<h2>Headers and Footers</h2>
<p>Most reports in a corporate setting come with some kind of standard header and/or footer. They can include anything from the date/time generated, the user who generated them, to page numbers and the like. Headers and footers are handy to have, but unfortunately there isn&#8217;t a real good way to add them to printable reports generated in HTML and CSS. There&#8217;s one more reason to use the portable document format when creating printable reports.</p>
<p>The process of adding headers and footers to a PDF using the R&amp;OS library is the slightest bit complicated. There are a lot of lines of code just to accomplish it, that&#8217;s why I have created a helper file. Since the code is in a helper function, you just need load the helper and call the function whenever you need to add headers/footers to a PDF.</p>
<pre class="brush: php">

function prep_pdf($orientation = &#039;portrait&#039;)
{
$CI = &amp;amp;amp;amp;amp;amp; get_instance();

$CI-&gt;cezpdf-&gt;selectFont(base_url() . &#039;/fonts&#039;);

$all = $CI-&gt;cezpdf-&gt;openObject();
$CI-&gt;cezpdf-&gt;saveState();
$CI-&gt;cezpdf-&gt;setStrokeColor(0,0,0,1);
if($orientation == &#039;portrait&#039;) {
$CI-&gt;cezpdf-&gt;ezSetMargins(50,70,50,50);
$CI-&gt;cezpdf-&gt;ezStartPageNumbers(500,28,8,&#039;&#039;,&#039;{PAGENUM}&#039;,1);
$CI-&gt;cezpdf-&gt;line(20,40,578,40);
$CI-&gt;cezpdf-&gt;addText(50,32,8,&#039;Printed on &#039; . date(&#039;m/d/Y h:i:s a&#039;));
$CI-&gt;cezpdf-&gt;addText(50,22,8,&#039;CI PDF Tutorial - http://www.christophermonnat.com&#039;);
}
else {
$CI-&gt;cezpdf-&gt;ezStartPageNumbers(750,28,8,&#039;&#039;,&#039;{PAGENUM}&#039;,1);
$CI-&gt;cezpdf-&gt;line(20,40,800,40);
$CI-&gt;cezpdf-&gt;addText(50,32,8,&#039;Printed on &#039;.date(&#039;m/d/Y h:i:s a&#039;));
$CI-&gt;cezpdf-&gt;addText(50,22,8,&#039;CI PDF Tutorial - http://www.christophermonnat.com&#039;);
}
$CI-&gt;cezpdf-&gt;restoreState();
$CI-&gt;cezpdf-&gt;closeObject();
$CI-&gt;cezpdf-&gt;addObject($all,&#039;all&#039;);
}
</pre>
<p>An example of how I use this helper is provided in the <strong>headers()</strong> function of the <strong>tutorial.php</strong> controller. That code produces a PDF file <a href="http://www.christophermonnat.com/wp-content/uploads/2008/07/headers.pdf">like this</a>.</p>
<p>The above code is the <strong>prep_pdf()</strong> function located in the <strong>pdf_helper.php</strong> file. This function does all the hard work of creating a footer for my PDF reports for me. All I have to do is load the helper in my controller and call the function. Since the reports could be portrait or landscape I have also included the ability to pass the orientation to the function and the code will modify the document margins accordingly.</p>
<p>I&#8217;m not going to go into a lot of detail about the above code because this tutorial could become very long. But the general idea is that I&#8217;m using the R&amp;OS library to modify the margins of the document I&#8217;m creating, add page numbers and text to the very bottom of the document. R&amp;OS has some functions that makes this easy like <strong>ezStartPageNumbers()</strong> and <strong>line()</strong>. Once all that is done I can add any kind of content to the document back in my controller and then just call <strong>ezStream()</strong> to generate the final document.</p>
<h2>Wrap Up</h2>
<p>I barely scratched the surface of what you can do with the R&amp;OS PDF library in this tutorial. I encourage you to spend some quality time with the <strong>readme.pdf</strong> documentation file that comes with the library when you download it. That file goes over all the functions and their options in great detail.</p>
<p>So there you have it, generating PDF files with CodeIgniter and the R&amp;OS library. If this method doesn&#8217;t quite do it for you, there are a few helpful articles on the CodeIgniter <a href="http://codeigniter.com/wiki/">wiki</a>, like <a href="http://codeigniter.com/wiki/PDF_generation_using_dompdf/">this one</a> and <a href="http://codeigniter.com/wiki/fpdf_CIed/">this one</a>, which walk you through some additional options. Whatever solution you choose I hope this tutorial has helped to introduce you to some of the options you have at your disposale for creating PDF reports with CodeIgniter.</p>


<p>Related posts:<ol><li><a href='http://www.christophermonnat.com/2009/05/building-applications-using-codeigniter-part-3-helpers/' rel='bookmark' title='Permanent Link: Building Applications using CodeIgniter (Part 3) &#8211; Helpers'>Building Applications using CodeIgniter (Part 3) &#8211; Helpers</a></li>
<li><a href='http://www.christophermonnat.com/2009/05/building-applications-using-codeigniter-part-4-code-templates/' rel='bookmark' title='Permanent Link: Building Applications using CodeIgniter (Part 4) &#8211; Code Templates'>Building Applications using CodeIgniter (Part 4) &#8211; Code Templates</a></li>
<li><a href='http://www.christophermonnat.com/2008/09/how-to-use-recaptcha-with-ci/' rel='bookmark' title='Permanent Link: How to use reCAPTCHA with CI'>How to use reCAPTCHA with CI</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.christophermonnat.com/2008/08/generating-pdf-files-using-codeigniter/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
	</channel>
</rss>
