<?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>Code Perspective &#187; Programming</title>
	<atom:link href="http://codeperspective.ca/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeperspective.ca</link>
	<description>Coding is awesome</description>
	<lastBuildDate>Wed, 25 Jan 2012 20:51:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Building a better singleton in Objective-C</title>
		<link>http://codeperspective.ca/2011/08/07/building-a-better-singleton-in-objective-c/</link>
		<comments>http://codeperspective.ca/2011/08/07/building-a-better-singleton-in-objective-c/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 06:29:00 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Iphone]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/?p=254</guid>
		<description><![CDATA[So I've found quite a few tutorials on writing singleton's in Objective-C online, however not many of them seem to be completely correct. The key to building a singleton in objective-c is synchronization. If you don't synchronize your threads then you might as well not build a singleton. Here is how it should be done...]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve found quite a few tutorials on writing singleton&#8217;s in Objective-C online, however not many of them seem to be completely correct. The key to building a singleton in objective-c is synchronization. If you don&#8217;t synchronize your threads then you might as well not build a singleton. Here is how it should be done&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> SharedManager<span style="color: #339933;">*</span> _sharedManager <span style="color: #339933;">=</span> nil<span style="color: #339933;">;</span></pre></div></div>

<p>Start by adding that line directly below your @implementation declaration.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Returns the shared instance
 */</span>
<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>SharedManager<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>sharedManager
<span style="color: #009900;">&#123;</span>
	@synchronized<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>SharedManager class<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>_sharedManager<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>self alloc<span style="color: #009900;">&#93;</span> init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> _sharedManager<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> nil<span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will allow you to create a shared instance of your class. In order to instantiate your class, you can now call -</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>SharedManager sharedManager<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Next we need to override alloc:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Overide alloc
 */</span>
<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>alloc
<span style="color: #009900;">&#123;</span>
	@synchronized<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>SharedManager class<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		NSAssert<span style="color: #009900;">&#40;</span>_sharedManager <span style="color: #339933;">==</span> nil<span style="color: #339933;">,</span> @<span style="color: #ff0000;">&quot;Attempted to allocate a second instance of a singleton.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		_sharedManager <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>super alloc<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> _sharedManager<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> nil<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Overriding alloc will allow us to completely control the state of our singleton, just be careful, you are now responsible for EVERY part of this class including memory deallocation. Finally, we override init to allow for any initialization/instantiating to occur.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Overide init
 */</span>
<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>init <span style="color: #009900;">&#123;</span>
&nbsp;
	self <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>super init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>self <span style="color: #339933;">!=</span> nil<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	    <span style="color: #666666; font-style: italic;">// initialize stuff here</span>
        <span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> self<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can initialize any variables you need where the comment &#8220;initialize stuff here&#8221;. That&#8217;s it! That&#8217;s all you need, remember to put these methods declarations into the .h so that the rest of your application can see them properly. Now you can add methods to your heart&#8217;s content.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>someMethodCall
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Do some stuff here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then to call your method all you have to do is the following:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>SharedManager sharedManager<span style="color: #009900;">&#93;</span> someMethodCall<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Remember to always add your method declarations to your header file and you&#8217;re finished.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2011/08/07/building-a-better-singleton-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Iphone Programming Part 2 &#8211; Intro to Views</title>
		<link>http://codeperspective.ca/2010/03/27/iphone-programming-part-2-intro-to-views/</link>
		<comments>http://codeperspective.ca/2010/03/27/iphone-programming-part-2-intro-to-views/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 19:32:45 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Iphone]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/?p=235</guid>
		<description><![CDATA[Welcome to iphone programming part 2, introduction to views. In this tutorial I'll go over creating an application from scratch that transitions between 2 different views using the iphone's built in UINavigationController and the navigation stack. If you haven't done so already, I suggest reading through my first iphone article. If you already have a basic understanding of how to create an iphone application and hooking up IBOulets and IBActions in interface builder then you can head straight into this article. So let's jump into it, and as always if you have any questions feel free to leave a comment and I'll get back to you.]]></description>
			<content:encoded><![CDATA[<p>Welcome to iphone programming part 2, introduction to views. In this tutorial I&#8217;ll go over creating an application from scratch that transitions between 2 different views using the iphone&#8217;s built in UINavigationController and the navigation stack. If you haven&#8217;t done so already, I suggest reading through my first iphone article. If you already have a basic understanding of how to create an iphone application and hooking up IBOulets and IBActions in interface builder then you can head straight into this article. So let&#8217;s jump into it, and as always if you have any questions feel free to leave a comment and I&#8217;ll get back to you.</p>
<p>Let&#8217;s start out by opening up XCode and creating a new window based application from the standard iphone OS templates. Save the file to wherever you save your iphone files to and create.</p>
<p style="text-align: center;"><a href="http://www.codeperspective.ca/images/ViewTransitionDemo/createNewWindow.png"><img class="aligncenter" title="CreateNewWindowApplication" src="http://www.codeperspective.ca/images/ViewTransitionDemo/createNewWindow.png" alt="" width="287" height="217" /></a>Once you create and save your new window-based application, open up the classes and resources folders in the XCode folder explorer. Open up the ViewDemoAppDelegate.h and insert the following code&#8230;</p>
<p style="text-align: left;">

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//  ViewDemoAppDelegate.h</span>
<span style="color: #666666; font-style: italic;">//  ViewDemo</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//  Created by Mark Hazlett on 10-03-26.</span>
<span style="color: #666666; font-style: italic;">//  Copyright Code Perspective 2010. All rights reserved.</span>
<span style="color: #666666; font-style: italic;">//</span>
&nbsp;
<span style="color: #339933;">#import &lt;UIKit/UIKit.h&gt;</span>
@interface ViewDemoAppDelegate <span style="color: #339933;">:</span> NSObject
<span style="color: #009900;">&#123;</span>
    UIWindow <span style="color: #339933;">*</span>window<span style="color: #339933;">;</span>
    UINavigationController <span style="color: #339933;">*</span>navController<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@property <span style="color: #009900;">&#40;</span>nonatomic<span style="color: #339933;">,</span> retain<span style="color: #009900;">&#41;</span> IBOutlet UIWindow <span style="color: #339933;">*</span>window<span style="color: #339933;">;</span>
&nbsp;
@end</pre></div></div>

<p>All we&#8217;re doing here is creating a UINavigationController object so that we can access it in our application delegate implementation file. Let&#8217;s go ahead and open up our ViewDemoAppDelegate.m and add the following code to the application did finish launching method.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>applicationDidFinishLaunching<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UIApplication <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>application
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Allocate and instatiate a new UINavigationController Object</span>
	navController <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>UINavigationController alloc<span style="color: #009900;">&#93;</span> init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Allocate and initialize a First View Controller Object</span>
	FirstViewController <span style="color: #339933;">*</span>firstViewController <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>FirstViewController alloc<span style="color: #009900;">&#93;</span>init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Push the first view controller onto the view controller stack without animation</span>
	<span style="color: #009900;">&#91;</span>navController pushViewController<span style="color: #339933;">:</span>firstViewController animated<span style="color: #339933;">:</span>NO<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Some memory management</span>
	<span style="color: #009900;">&#91;</span>firstViewController release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Make it visible</span>
	<span style="color: #009900;">&#91;</span>window	addSubview<span style="color: #339933;">:</span>navController.<span style="color: #202020;">view</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Override point for customization after application launch</span>
    <span style="color: #009900;">&#91;</span>window makeKeyAndVisible<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The first thing we&#8217;re doing in this function is instantiating the UINavigationController that we declared in our header. We pass it an alloc and init to allocate the appropriate amount of memory for it as well as an init to initialize it properly. The next thing we&#8217;re going to do is create a new FirstViewController object. Now you may be asking what a FirstViewController object is? That&#8217;s because we haven&#8217;t created it yet. So let&#8217;s go ahead and go to &#8220;File &gt; New File&#8221; and add a new file that&#8217;s of the type UIViewController subclass. Make sure you check the little check box that says &#8220;With XIB for user interface&#8221;. This will give you an XIB file to work with instead of producing your interface programmatically. Now that we have our FirstViewControllerObject the only thing we have to do is import the header into the ViewDemoAppDelegate. So make sure to declare #import &#8220;FirstViewController.h&#8221; at the top of your code. Now onto the rest of the code in our application did finish launching method. The first thing we do with our allocated view controller is push it onto the navigation stack. Now because this is our first view we&#8217;re pushing onto the navigation stack we want to make sure to pass &#8220;NO&#8221; to the animated parameter because we don&#8217;t want to animate the root view when it&#8217;s pushed onto the stack. Now for some memory management. Once the FirstViewController is pushed onto the navigation stack the retain count on the object moves up to 2, therefore we can perform a release on the FirstViewController object so that the retain count stays at 1. Last thing we do in this method is add the view so our window so that it&#8217;s actually visible when we load the application.</p>
<p>Now we&#8217;re going to get into some interface builder stuff. Let&#8217;s start by opening up our FirstViewController.xib file in Interface Builder(or by just double clicking on it). You should see just a plain white view. Now in order to transition between views we need a button to press to actually transition between views. So let&#8217;s go ahead and add a UIButton to the view. Label the button anything you would like to to transition between views. Go ahead and save that file for now(we&#8217;ll come back to it later to connect the pointers). Next we&#8217;re going to create a new file in our project that&#8217;s a subclass of UIViewController. Again we&#8217;re going to make sure that &#8220;use XIB for user interface&#8221; is selected and press create. We&#8217;re going to name this view controller &#8220;SecondViewController&#8221; as it&#8217;s the one that we transition to from pressing the button on our first view controller. Once you create the new View Controller you should see it appear on the left hand side in your package explorer. Let&#8217;s go into our FirstViewController.h and add the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &lt;UIKit/UIKit.h&gt;</span>
@interface FirstViewController <span style="color: #339933;">:</span> UIViewController
<span style="color: #009900;">&#123;</span>
	IBOutlet UIButton <span style="color: #339933;">*</span>transitionButton<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span> pushViewContoller<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> send<span style="color: #339933;">;</span>
&nbsp;
@end</pre></div></div>

<p>All we do here is create an IBOutlet for the UIButton we added to the XIB file and call it transition button. Then we create an IBAction method that will get called whenever the user presses inside the UIButton. Let&#8217;s open up our FirstViewController.m implementation file and implement the IBAction method like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &quot;FirstViewController.h&quot;</span>
<span style="color: #339933;">#import &quot;SecondViewController.h&quot;</span>
&nbsp;
@implementation FirstViewController
&nbsp;
<span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span> pushViewContoller<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> send
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Allocate and instantiate the second view controller object</span>
	SecondViewController <span style="color: #339933;">*</span>secondView <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>SecondViewController alloc<span style="color: #009900;">&#93;</span> init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Push the secondViewController onto the navigation stack</span>
	<span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">navigationController</span> pushViewController<span style="color: #339933;">:</span>secondView animated<span style="color: #339933;">:</span>YES<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Some memory management</span>
	<span style="color: #009900;">&#91;</span>secondView release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now as you can see, we first provide our implementation with an import of the SecondViewController.h that we created earlier. We then proceed to allocate and instantiate our SecondViewController object. This time we&#8217;re going to push it onto our navigation stack and passing the YES parameter to our animated option because this time we do want it to be be animated when we press the button. After that we just provide some basic memory management to bring the retain count of the SecondViewController object back down to 1. That&#8217;s al the necessary code we need right now, however if you run this program right now you&#8217;ll notice that if you press the button on the first view controller it won&#8217;t really do anything. So let&#8217;s open back up our FirstViewController.xib file and hook up our IBOutlet and IBAction to our button that we created. After you&#8217;re finished hooking up these actions in the File&#8217;s owner connections inspector, the file&#8217;s owner connections inspector should look something like this..</p>
<p><a href="http://www.codeperspective.ca/images/ViewTransitionDemo/completedConnectionInspec.png"><img class="aligncenter" title="Completed Connections Inspec" src="http://www.codeperspective.ca/images/ViewTransitionDemo/completedConnectionInspec.png" alt="" width="301" height="247" /></a>Now you should be able to run the application and press the button and see the transition to the second view controller(which will be blank unless you added something to the nib) and press the back button in the navigation controller and transition back to the first screen.</p>
<p>If you&#8217;re having some troubles, here is the project and all the code. <a title="View Demo Download" href="http://codeperspective.ca/ViewDemo.zip" target="_blank">Download</a></p>
<p>Also again, if you have any questions feel free to leave them in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2010/03/27/iphone-programming-part-2-intro-to-views/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Installing Cocos2D for the iphone</title>
		<link>http://codeperspective.ca/2010/03/09/installing-cocos2d-for-the-iphone/</link>
		<comments>http://codeperspective.ca/2010/03/09/installing-cocos2d-for-the-iphone/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 21:34:36 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Iphone]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/?p=229</guid>
		<description><![CDATA[I have recently started working on some Iphone games only to discover a spectacular 2D game engine on the iphone called Cocos2D. After reading their very impressive feature list and some blogs on how Cocos2D works, I decided to try it out for myself. Low and behold however that it wasn't the easiest thing to install manually for iphone development. If you try and install cocos manually, you will run into countless errors and hassles while getting it up and running.]]></description>
			<content:encoded><![CDATA[<p>I have recently started working on some Iphone games only to discover a spectacular 2D game engine on the iphone called <a title="Cocos2D" href="http://cocos2d.org/" target="_blank">Cocos2D</a>. After reading their very impressive feature list and some blogs on how Cocos2D works, I decided to try it out for myself. Low and behold however that it wasn&#8217;t the easiest thing to install manually for iphone development. If you try and install cocos manually, you will run into countless errors and hassles while getting it up and running.</p>
<p>However, Cocos2D now sports a fancy shell script to get some Cocos2D templates up and running directly in Xcode with all the files pre-configured to start. To install these templates all you have to do is navigate to the cocos2D root directory on your filesystem using the terminal and then run this command.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">./install_template.sh</pre></div></div>

<p>You can then open Xcode and you should see the following screen ready to use.</p>
<p style="text-align: center;">
<p style="text-align: center;"><a style="text-decoration: none;" href="http://codeperspective.ca/images/XCodePart1/cocos2d.png"><img class="aligncenter" title="Cocos2D" src="http://codeperspective.ca/images/XCodePart1/cocos2d.png" alt="" width="595" height="569" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2010/03/09/installing-cocos2d-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Intro to PHP &#8211; Creating a Basic Login System</title>
		<link>http://codeperspective.ca/2009/12/13/intro-to-php-creating-a-basic-login-system/</link>
		<comments>http://codeperspective.ca/2009/12/13/intro-to-php-creating-a-basic-login-system/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 04:43:18 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/?p=181</guid>
		<description><![CDATA[Using a little knowledge of PHP and HTML you can build a simple log in system for your site. In order to correctly follow this tutorial you may want to have a good idea of basic HTML/PHP syntax as well as knowing some CSS. You should also have a basic understanding of how to create and use sessions($_SESSIONS) in PHP.]]></description>
			<content:encoded><![CDATA[<p>Using a little knowledge of PHP and HTML you can build a simple log in system for your site. In order to correctly follow this tutorial you may want to have a good idea of basic HTML/PHP syntax as well as knowing some CSS. You should also have a basic understanding of how to create and use <a title="Intro to PHP - Using Sessions and cookies" href="http://codeperspective.ca/2009/12/09/intro-to-php-intro-to-sessions-and-cookies/" target="_blank">sessions($_SESSIONS) in PHP</a>.</p>
<p>Alright let&#8217;s get started by just creating a basic log in window and place it in the center of the screen. First the log in window.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Sample Log In<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loginCSS.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;outerLimit&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;innerLimit&quot;</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loginBox&quot;</span>&gt;</span>
						<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;login&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;login&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;userAuth.php&quot;</span>&gt;</span>
							<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;username&quot;</span>&gt;</span>Username:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
							<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
							<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span>&gt;</span>Password:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
							<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
							<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Log In&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
						<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
						<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Next let&#8217;s move into a bit of the CSS. Basically we just want to create a window with a gray background so the fields are extremely easy to see. I called the CSS file in this case loginCSS.css but you can call it whatever you like as long as it&#8217;s referenced properly in the HTML  section.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">468px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">min-width</span><span style="color: #00AA00;">:</span><span style="color: #933;">552px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span>Helvetica<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
a
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span>small<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#loginBox</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#e4e4e4</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">25%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">25%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#outerLimit</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span>table<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#container</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">table-cell</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">468px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#innerLimit</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">552px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">468px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>As you can see, I just styled the page a little bit to make it a little bit easier for the user to use. Now that we have a basic page for the user to log in, we&#8217;ll also need a page, such as a dashboard, for the user to access when they enter in correct login criteria. In this case we&#8217;re just going to use a page that has a basic header telling the user they have logged in correctly. The page can look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Sample Log In<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loginCSS.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>You are now logged in!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;logout.php&quot;</span>&gt;</span>Log Out Here<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>As you can see I have also included a log out link just below the h1 tag. If a user logs into the system we also want them to be able to log out. Next we&#8217;re going to create the SQL for our database. For this tutorial I&#8217;ll be using MySQL, however Oracle or SQL Server could also be used.</p>
<p>Note: If you&#8217;re going to use a different database then the code to connect to the database will be slightly different.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">'testDB'</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">'user'</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">'testDB'</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">'user'</span>
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #ff0000;">'username'</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #ff0000;">'password'</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">'testDB'</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">'user'</span>
<span style="color: #66cc66;">&#40;</span>username<span style="color: #66cc66;">,</span> password<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'admin'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'password'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'guest'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'password'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This is just a very simple database table that contains only a username and password. This script could obviously be modified to accept further fields of to encrypt the password field to increase the security of your system. Things like that will be out of the scope of this tutorial however.</p>
<p>Now that we have our environment set up we can start to use PHP to get data from the forms and compare them with the database. For the this tutorial we will only be using the POST method of retrieving data from forms. Using GET is often not recommended when getting sensitive data such as usernames and passwords. As you can see from the log in window, we have used the POST method to get the data, and when the form is submitted we are calling the userAuth.php file. Let&#8217;s go ahead and create that file now.</p>
<p>This block of code we will be using to check to see if the fields are blank. If they are we want to send them back to the login.html file to log back in again using the header() function. Next we want to enter all the configuration information to connect to the database and use some PHP functions to protect our site from SQL injection errors.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*Create the variables to hold the database information*/</span>
&nbsp;
<span style="color: #000088;">$dbName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;testDB&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*Table name that we're checking against*/</span>
&nbsp;
<span style="color: #000088;">$dbTable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*Database username*/</span>
&nbsp;
<span style="color: #000088;">$dbUsername</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DBUsername&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*Database Password*/</span>
&nbsp;
<span style="color: #000088;">$dbPassword</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DBPassword&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</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;">/*This next block is to prevent SQL injection hacks*/</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$username</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;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</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;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I have put in default values into the variables. Variables such as $dbTable and $dbUsername will be subject to change based on your database configuration. These values will need to be filled in with correct values from your system. Next we&#8217;re going to be connecting to the database and opening a connection.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*Connect to the Database*/</span>
&nbsp;
<span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbUsername</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbPassword</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*Select the database you want to access*/</span>
&nbsp;
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$connection</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*Select statement from the database to see if the user is in the system*/</span>
&nbsp;
<span style="color: #000088;">$sqlQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT COUNT(*) FROM <span style="color: #006699; font-weight: bold;">$table_name</span> WHERE username = '<span style="color: #006699; font-weight: bold;">$username</span>'
AND password = password('<span style="color: #006699; font-weight: bold;">$password</span>')&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*Create a variable to hold the results of the SQL query*/</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlQuery</span><span style="color: #339933;">,</span> <span style="color: #000088;">$connection</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*Check the number of rows returned from the query*/</span>
&nbsp;
<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now we&#8217;re getting to the user authentication section. We&#8217;re now going to see if the number of rows that was selected is anything but 0. In theory it should ever only come back with 1 or 0 rows, however in systems where users can multiple accounts it&#8217;s good to keep it to != 0.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*If the number of rows is not equal to 0 then authenticate the user*/</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</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: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Create a session for the username and password</span>
	<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</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: #339933;">!</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:login.html&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;">//because the user is authenticated move them to the dashboard</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: home.html&quot;</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;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: login.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</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>We then register a session and store the username and password in the session. If the session has been registered correctly then you can send the user to the home screen. If the session is not registered correctly for some reason we don&#8217;t want the users accessing the system, so we send them back to the login screen to attempt to log in again.</p>
<p>That&#8217;s it, an entire login system. Of course this is just meant to give you the idea of the steps and should by no means be used in a real-world system as is. However you should have a firm understanding of how a basic login system works using PHP/MySQL and a little bit of HTML and CSS. As always if you have any questions/concerns feel free to leave a comment and I&#8217;ll get back to you asap.</pre>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2009/12/13/intro-to-php-creating-a-basic-login-system/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JQuery Part 4 &#8211; Intro to CSS Manipulation</title>
		<link>http://codeperspective.ca/2009/12/10/jquery-part-4-intro-to-css-manipulation/</link>
		<comments>http://codeperspective.ca/2009/12/10/jquery-part-4-intro-to-css-manipulation/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 21:37:24 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/?p=179</guid>
		<description><![CDATA[JQuery is often used in websites to manipulate the CSS attributes of an HTML element upon the users request. For example, if a user wants to increase the size of the font immediately so that they can read your page, or you may just want to change up the CSS on the fly to make your page stand out a little more. All these things can be done in JQuery using the css() function and css manipulation techniques. Let's get started by creating a basic page with a link and a paragraph with some links in it like so...]]></description>
			<content:encoded><![CDATA[<p>JQuery is often used in websites to manipulate the CSS attributes of an HTML element upon the users request. For example, if a user wants to increase the size of the font immediately so that they can read your page, or you may just want to change up the CSS on the fly to make your page stand out a little more. All these things can be done in JQuery using the css() function and css manipulation techniques. Let&#8217;s get started by creating a basic page with a link and a paragraph with some links in it like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lib/jquery/jquery-1.3.2.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>JQuery CSS Manipulation<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Click Me<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam sit amet elit vitae arcu interdum ullamcorper. Nullam ultrices, nisi quis scelerisque convallis, <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>augue neque<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> tempor enim, et mattis justo nibh eu elit. Quisque ultrices gravida pede. Mauris accumsan vulputate tellus. Phasellus condimentum bibendum dolor. Mauris sed ipsum. Phasellus in diam. Nam sapien ligula, consectetuer id, <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>hendrerit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> in, cursus sed, leo. Nam tincidunt rhoncus urna. Aliquam id massa ut nibh bibendum imperdiet. Curabitur neque mauris, porta vel, lacinia quis, placerat ultrices, orci.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>As you can see it&#8217;s a basic HTML page that references the JQuery script. We have also added a link that says &#8220;click me&#8221; along with a paragraph of lorem ipsum text with some links in it. Alright, now onto creating the CSS for the page. For this example I will be putting the CSS in the header but if you want to put it in an external file by all means go ahead and reference it in the header.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>		
p a
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>As you can see, I just added an attribute to make all the links within the paragraph tags initially turn up as red. You can add as many CSS elements here as you would like to style the links however you like but for the purpose of this demonstration you will just need the color red as an attribute. Next let&#8217;s add the JQuery and introduce the .css() function.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'p a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'blue'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>As you can see the JQuery code is pretty straight forward for what we&#8217;re doing. Basically we&#8217;re starting out by checking the DOM to make sure that the file is ready to be manipulated. Then, we perform a click function anytime an anchor tag is pressed. Inside of that click function is where we actually manipulate the CSS and change the color of the anchor tags to blue instead of red like we originally set. The css() function accepts two parameters that we&#8217;ll be using. The first is the attribute that you would like to change and the second is the attribute that you want to change it to. So for our example, the attribute is the color and we&#8217;re going to change it to blue. If of course you want to change the color of the link that was originally pressed instead of every link inside the paragraph tags you could use the &#8220;this&#8221; function instead of specifying a specific tag.</p>
<p>That&#8217;s the basics to CSS manipulation using JQuery, of course the example shown here is only a very basic example and can be greatly expanded upon. This is what the final code should look like&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lib/jquery/jquery-1.3.2.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>JQuery Test<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>		
			p a
			{
				color: red;
			}
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
			$(function()
			{
				$('a').click(function()
				{
					$('p a').css('color', 'blue');
				});
			});
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;box&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Click Me<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam sit amet elit vitae arcu interdum ullamcorper. Nullam ultrices, nisi quis scelerisque convallis, <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>augue neque<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> tempor enim, et mattis justo nibh eu elit. Quisque ultrices gravida pede. Mauris accumsan vulputate tellus. Phasellus condimentum bibendum dolor. Mauris sed ipsum. Phasellus in diam. Nam sapien ligula, consectetuer id, <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>hendrerit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> in, cursus sed, leo. Nam tincidunt rhoncus urna. Aliquam id massa ut nibh bibendum imperdiet. Curabitur neque mauris, porta vel, lacinia quis, placerat ultrices, orci.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2009/12/10/jquery-part-4-intro-to-css-manipulation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JQuery Part 3 &#8211; Intro to Functions</title>
		<link>http://codeperspective.ca/2009/10/31/jquery-part-3-intro-to-functions/</link>
		<comments>http://codeperspective.ca/2009/10/31/jquery-part-3-intro-to-functions/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 00:24:00 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/?p=150</guid>
		<description><![CDATA[Often when writing JQuery code(especially for plugins) there are times when you need to execute the same block of code multiple times. Instead of writing them all out individually and making our code really terrible process wise, we can use functions and function calls to call the same block of code over and over.]]></description>
			<content:encoded><![CDATA[<p>This is part 3 in a series of JQuery tutorials. I strongly recommend at least reading <a href="http://codeperspective.ca/2009/10/28/introduction-to-jquery-part-1/">Part 1</a> before continuing with this tutorial. <a href="http://codeperspective.ca/2009/10/29/jquery-part-2-basic-animation/">Part 2</a> is optional but would also be a great background before we get started. As for this tutorial, I will be going over creating an executing functions to make your code more efficient.</p>
<p>Often when writing JQuery code(especially for plugins) there are times when you need to execute the same block of code multiple times. Instead of writing them all out individually and making our code really terrible process wise, we can use functions and function calls to call the same block of code over and over.</p>
<h3>Creating Functions</h3>
<p>You can create a function in 2 different places. The first is in the same script tags, but not inside the document ready function. Or second, you could create a brand new script file and then reference that script file in your header. Inside this script file you could create your method and it would be able to be accessed by the main file.</p>
<p>To create a function, the syntax looks like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> nameOfFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//your code here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This tells the browser that there is a function called nameOfFunction that is not being passed any parameters. Passing parameters is something I&#8217;ll get into a little bit later. Now say you wanted to alert the user with a javascript pop-up box every time this function was run. You could add some code into the function to allow a dialog box to appear like so.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> nameOfFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;We are now alerting the user!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Executing Functions</h3>
<p>Now that we have a function created, we need to somehow call that function to execute. That&#8217;s where our javascript method calls come in. Let&#8217;s say we wanted to execute the previous function. The code would look like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	nameOfFunction<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;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Of course this would call the function immediately after the page was ready. You can use a function call in JQuery in any function. So if you wanted to add it inside of a .click function you could do that as well. That&#8217;s all you need to do to execute functions in JQuery.</p>
<h3>Passing Arguments to Functions</h3>
<p>Let&#8217;s say you wanted a function to work with a piece of data from a form, but you didn&#8217;t want the function to retrieve that piece of data inside the function. You can use a piece of code called an argument to pass to the function. This allows you to pass values to a function so they can be used. To create a function with an argument then all you need to do is add the argument into the brackets in the function header. It looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> nameOfFunction<span style="color: #009900;">&#40;</span>argument<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//your code here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now obviously since we have that argument in the argument ready to do something with it, we may also want to return a value back to the original function so that we can maybe display the result of a calculation or something like that. If we want to return a value all we have to do is insert a return value into our function.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> nameOfFunction<span style="color: #009900;">&#40;</span>argument<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> total <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span> <span style="color: #339933;">+</span> argument<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> total<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This function will now accept a value, add 10 to that value and return it to the original function call. This way if we need to manipulate some data quite a few times, we could use a function to do that display the result.</p>
<h3>Function Calls with Arguments</h3>
<p>Now that we have a function made that&#8217;s accepting an argument and returning a value, we can use a function call and pass an argument to the function so it can do the calculation and we can then display the result. The function call looks something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;The total is = &quot;</span> <span style="color: #339933;">+</span> nameOfFunction<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In our JQuery ready function we are now just displaying an alert. Inside the alert we are actually making the function call and passing a value of 10 to our function. The function is then going to add 10 to our passed argument and return a value of 20. The alert therefore is going to display &#8211; &#8220;The total is = 20&#8243;. And that&#8217;s all for basic functions and function calls.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2009/10/31/jquery-part-3-intro-to-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>13 must have apps for Mac OS X developers</title>
		<link>http://codeperspective.ca/2009/07/03/13-must-have-apps-for-mac-os-x-developers/</link>
		<comments>http://codeperspective.ca/2009/07/03/13-must-have-apps-for-mac-os-x-developers/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 22:37:30 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/blog/?p=46</guid>
		<description><![CDATA[1. Apple Developer Tools &#8211; These are just a no-brainer here. There is a huge arsenal of apps that come standard with every mac that absolutely EVERY developer that is developing for mac os x needs. Xcode, Dashcode, Instruments, Interface Builder, etc. There are a ton more to check out if you haven&#8217;t already, and [...]]]></description>
			<content:encoded><![CDATA[<p>1. <a href="http://developer.apple.com/Tools/">Apple Developer Tools</a> &#8211; These are just a no-brainer here. There is a huge arsenal of apps that come standard with every mac that absolutely EVERY developer that is developing for mac os x needs. Xcode, Dashcode, Instruments, Interface Builder, etc. There are a ton more to check out if you haven&#8217;t already, and all of them will considerably ease your development experience on OS X.</p>
<p>2. <a href="http://www.eclipse.org/">Eclipse</a>- Eclipse is the ideal application for java development on Mac OS X. With the amount of features that eclipse offers, it&#8217;s almost impossible to skip this application if you do any level of java development. The &#8220;intellisense&#8221; that eclipse includes while you&#8217;re coding is unprecedented. </p>
<p>3. <a href="http://www.adobe.com/products/photoshop/compare/">Photoshop/ Gimp</a> &#8211; This is a must have for any type of website development/interface development. Whether it&#8217;s doing website mockups or drawing new buttons for your application, this is a must have.</p>
<p>4. <a href="http://www.panic.com/coda/">Coda</a> &#8211; I can&#8217;t speak enough good things about coda. This application has exceeded my expectations in every way possible. Whether it&#8217;s through the handy &#8220;sites&#8221; feature, or connecting to a server using the built in console, this is by far the best web development app for Mac OS X. Well worth the 100 bucks!</p>
<p>5.<a href="http://www.utorrent.com/">uTorrent</a> &#8211; A very simple torrent application. Extremely easy to use and very efficient. Having the ability to select which files you want to download and which you don&#8217;t is a huge bonus.</p>
<p>6. <a href="http://adium.im/">Adium</a> &#8211; A very powerful messenger application for Mac OS X. From IRC plugins, to customizing the look and feel, Adium can pretty much do it all.</p>
<p>7. <a href="http://www.jingproject.com/">Jing</a> &#8211; This screen capture application hides almost out of sight in your menu bar but packs some powerful features. Jing has the ability to capture screen casts of your applications in action as well as screen shots. Great App!</p>
<p>8. <a href="http://www.qtsoftware.com/products/developer-tools">QT Creator</a> &#8211; From the designer&#8217;s of the famous UI toolkit QT comes their first IDE. QT Creator is a fantastic IDE for developing QT Apps. From the WYSIWYG editor to the syntax editor, great app all around.</p>
<p>9. <a href="http://prism.mozilla.com/">Prism</a> &#8211; Pretty cool new(ish) app from Mozilla. This application allows you to capture sites like gmail and make them into a desktop application so you don&#8217;t have to open a browser every time you want to say check your email.</p>
<p>10. <a href="http://www.islayer.com/apps/istatmenus/">iStat Menu&#8217;s</a> &#8211; This light-weight app will allow you to truly track your applications performance and see if you potentially have a memory leak in your app. Has a separate monitor for each CPU to allow the user to see what&#8217;s going on in each CPU at any given time. A must have even for non-developers.</p>
<p>11. <a href="http://www.xmind.net/">XMind</a> &#8211; This extremely powerful mind-mapping tool is great for those pre-alpha stages of development. Getting as many ideas down as quick as possible is extremely easy for this application to handle. The application is based on the eclipse platform and is very solid.</p>
<p>12. <a href="http://www.virtualbox.org/">Virtual Box</a> &#8211; This open source application is great for testing applications in numerous environments. Test run your apps on Linux, Windows, BSD and more. </p>
<p>13. <a href="http://www.vmware.com/products/fusion/">VmWare Fusion</a> &#8211; This is a must have for all developers but especially for those doing web development with coda. Allows you to run windows applications natively on Mac OS X. Another great app for testing in multiple environments as well.</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2009/07/03/13-must-have-apps-for-mac-os-x-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft and Open Source</title>
		<link>http://codeperspective.ca/2009/04/04/microsoft-and-open-source/</link>
		<comments>http://codeperspective.ca/2009/04/04/microsoft-and-open-source/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 04:36:17 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Industry News]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/blog/?p=32</guid>
		<description><![CDATA[As some of you may know I am an open source advocate. The ability to modify and change the source code of your application to make it work the way you want to is a huge plus. With Microsoft being one of many companies that keeps it's doors closed when it comes to it's source code, it makes it extremely difficult to maintain a trustworthy relationship between customers and developers. ]]></description>
			<content:encoded><![CDATA[<p>As some of you may know I am an open source advocate. The ability to modify and change the source code of your application to make it work the way you want to is a huge plus. With Microsoft being one of many companies that keeps it&#8217;s doors closed when it comes to it&#8217;s source code, it makes it extremely difficult to maintain a trustworthy relationship between customers and developers. </p>
<p>Recently however, Microsoft has released the ASP.NET source code. The article found <a href="http://weblogs.asp.net/scottgu/archive/2009/04/01/asp-net-mvc-1-0.aspx">here</a> outlines the details of the release.</p>
<p>I do think that a bigger step is needed to fully gain the acceptance of the open source community. However i do think it is a major step in the right direction. I would like to see another major jump for other companies to go the open source route. Customers having the ability to review the source code to make sure there are not &#8220;hooks&#8221; inside the code. I think by doing this, customers of Microsoft will have eventually begin to regain the company&#8217;s trust. But, I&#8217;m not sure it will be in time. </p>
<p>Cheers</p>
<p><!--digg--></p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2009/04/04/microsoft-and-open-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Application Specific Console in QT Jambi</title>
		<link>http://codeperspective.ca/2009/03/16/creating-an-application-specific-console-in-qt-jambi/</link>
		<comments>http://codeperspective.ca/2009/03/16/creating-an-application-specific-console-in-qt-jambi/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 04:22:25 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[QT]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/blog/?p=30</guid>
		<description><![CDATA[I am currently working on a project that required a console with a very specific purpose. It needed to communicate with a custom back-end protocol for use in a client/server environment. This sort of specific tutorial is not surprisingly unavailable online. The first step when setting up an application specific console is actually setting up [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a project that required a console with a very specific purpose. It needed to communicate with a custom back-end protocol for use in a client/server environment. This sort of specific tutorial is not surprisingly unavailable online. The first step when setting up an application specific console is actually setting up the back-end. This is something that will be potentially done as a future tutorial. Anyways back to building the console window. The components included in the console window will be one QTextEdit, and one QLineEdit. This can be constructed in any way you like. The QTextEdit can be on the bottom and the QLineEdit on top or the other way around, that&#8217;s up to you. </p>
<p>Next, we will need to be adding a custom action listener to the QLineEdit so that when the enter key is pressed inside the QLineEdit the command will be sent to the server and then displayed in the QTextEdit window. As a future feature implementation, syntax highlighting could be implemented for an easier display inside the QTextEdit window. The custom action listener to add to the QLineEdit bar looks like this&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">QLineEdit.<span style="color: #006633;">returnPressed</span>.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;NameOfActionListenerMethod()&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This will ensure that everytime the enter button is pressed, the string that the user entered will be able to be transfered to the server, or wherever else in the program you would like it to go. Now for the action listener method. The method should be declared as public with a return type of void.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> terminalWindowEnterPressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        terminalWindow.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>enterArea.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        enterArea.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Protocol Name &gt; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Then once you have the action listener built to just send the data to the window, you can do the same with sending it across a network.</p>
<p>All Together the code looks like this. All you have to do is copy/paste the code into your program and use it at will.</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> buildTerminal<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        terminalFrame <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> QFrame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        terminalFrame.<span style="color: #006633;">setWindowTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Window Title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        terminalWindow <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> QTextEdit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        terminalWindow.<span style="color: #006633;">setReadOnly</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        enterArea <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> QLineEdit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        enterArea.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Protocol Name &gt; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        enterLabel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> QLabel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Enter Command&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        terminalFrame.<span style="color: #006633;">setMinimumSize</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">600</span>, <span style="color: #cc66cc;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        enterArea.<span style="color: #006633;">returnPressed</span>.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;terminalWindowEnterPressed()&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        QGridLayout layout <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> QGridLayout<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        layout.<span style="color: #006633;">addWidget</span><span style="color: #009900;">&#40;</span>terminalWindow,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        layout.<span style="color: #006633;">addWidget</span><span style="color: #009900;">&#40;</span>enterArea,<span style="color: #cc66cc;">11</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        layout.<span style="color: #006633;">addWidget</span><span style="color: #009900;">&#40;</span>enterLabel, <span style="color: #cc66cc;">11</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        terminalFrame.<span style="color: #006633;">setLayout</span><span style="color: #009900;">&#40;</span>layout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        terminalFrame.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> terminalWindowEnterPressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        terminalWindow.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>enterArea.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        enterArea.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Protocol Name &gt; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Cheers</p>
<p><!--digg--></p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2009/03/16/creating-an-application-specific-console-in-qt-jambi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Program Design</title>
		<link>http://codeperspective.ca/2009/03/01/program-design/</link>
		<comments>http://codeperspective.ca/2009/03/01/program-design/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 03:56:34 +0000</pubDate>
		<dc:creator>Mark Hazlett</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://codeperspective.ca/blog/?p=26</guid>
		<description><![CDATA[So in school, we are learning some fundamentals on object oriented design in Java such as inheritance and polymorphism. The thing that we haven&#8217;t done is the actual concept of object oriented design. So things like how to structure classes and methods for optimal code efficiency and use. This is such a fundamental concept to [...]]]></description>
			<content:encoded><![CDATA[<p>So in school, we are learning some fundamentals on object oriented design in Java such as inheritance and polymorphism. The thing that we haven&#8217;t done is the actual concept of object oriented design. So things like how to structure classes and methods for optimal code efficiency and use. This is such a fundamental concept to teach in school to allow programmers just coming out of school to produce optimized and efficient code. </p>
<p>It&#8217;s no matter in today&#8217;s society we deal with so many programs that crash and don&#8217;t work properly. If fundamental programming techniques such as design are not being taught, then when students graduate it is to be expected that they continue the programming practices that they picked up in college/university. </p>
<p>This being said, when you come out of college/university, you&#8217;re most likely to have a &#8220;code monkey&#8221; position, where you&#8217;re actually coding the enterprise applications. So it&#8217;s almost expected, knowing this that programs you use everyday crash on such a regular basis.</p>
<p>Cheers</p>
<p><!--digg--></p>
]]></content:encoded>
			<wfw:commentRss>http://codeperspective.ca/2009/03/01/program-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

