<?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>17 Webshop&#187; 17 Webshop</title>
	<atom:link href="http://17webshop.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://17webshop.com</link>
	<description>Web Design + Development</description>
	<lastBuildDate>Thu, 10 Dec 2009 16:04:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Filters and How to Use Them</title>
		<link>http://17webshop.com/2009/12/10/php-filters-and-how-to-use-them/</link>
		<comments>http://17webshop.com/2009/12/10/php-filters-and-how-to-use-them/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 07:44:42 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[callback]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[sanitize]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[user input]]></category>
		<category><![CDATA[validate]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=495</guid>
		<description><![CDATA[PHP really shows its true colors when it comes to how easy it is to learn&#8211;especially for new programmers. However, as result of this new coders often overlook a lot of really useful functionality that PHP has to offer, particularly when it comes to securing our scripts. Today we&#8217;re going to take a look at [...]]]></description>
			<content:encoded><![CDATA[<p>PHP really shows its true colors when it comes to how easy it is to learn&#8211;especially for new programmers. However, as result of this new coders often overlook a lot of really useful functionality that PHP has to offer, particularly when it comes to securing our scripts. Today we&#8217;re going to take a look at PHP filters and how easy it is to use them to increase our script&#8217;s security.</p>
<p><span id="more-495"></span></p>
<h3>What Are PHP Filters?</h3>
<p>If you have <em>ever</em> written <em>any</em> script that has been in public use, you should know to <strong>never trust the user</strong>, PHP filters step in to help solve this problem. PHP filters are implemented through the PHP Filter Extension. The Filter Extension is a rather thorough library of pre-defined rules you can use to clean user input and prepare data for database storage or any number of other implementations you may come across.</p>
<h3>How Do PHP Filters Work?</h3>
<p>PHP filters work through a couple of built-in functions, namely <code>filter_var()</code> and <code> filter_var_array()</code>, and flags you pass to these methods. The flag you pass these functions will determine which filter you want to implement.</p>
<p>There are two types of filters, validation and sanitization filters. Validation filters are similar to a true/false type check. When using a validation filter, the function will return the original data you passed it if the data passed the validation check. When using sanitization filters, the function will return the data you passed it after it removes the necessary data to make it pass the test.</p>
<p>To see what filters are supported in your environment, there is a nifty function <code>filter_list()</code>. Example:</p>
<pre name="code" class="php">

print_r(filter_list());

//prints...

Array
(
    [0] => int
    [1] => boolean
    [2] => float
    [3] => validate_regexp
    [4] => validate_url
    [5] => validate_email
    [6] => validate_ip
    [7] => string
    [8] => stripped
    [9] => encoded
    [10] => special_chars
    [11] => unsafe_raw
    [12] => email
    [13] => url
    [14] => number_int
    [15] => number_float
    [16] => magic_quotes
    [17] => callback
)
</pre>
<p>These are the filters that are supported on my server, yours may be different. We&#8217;re going to take a look at a few examples of what you can do with these filters.</p>
<p>If you would like more information on the <code>filter_var()</code> and <code> filter_var_array()</code> functions, check out the PHP manual entries for these functions for more information about them specifically: <code><a href="http://us.php.net/manual/en/function.filter-var.php">filter_var()</a></code>, <code><a href="http://us.php.net/manual/en/function.filter-var-array.php">filter_var_array()</a></code>.</p>
<h3>Useful PHP Validation Filters</h3>
<p><strong>Validating Integers</strong></p>
<p>You can validate integer with the <code>FILTER_VALIDATE_INT</code> flag. If you pass the function an integer, it will return it just like it came. However, if you pass it say, a string or a float data type it will return NULL or FALSE.</p>
<pre name="code" class="php">

$var = 473;

filter_var($var, FILTER_VALIDATE_INT); //returns 473

$var = 'hello';

filter_var($var, FILTER_VALIDATE_INT); //returns FALSE

$var = 71.4;

filter_var($var, FILTER_VALIDATE_INT); //returns FALSE
</pre>
<p>You can also specify options for the <code>FILTER_VALIDATE_INT</code> flag, like min, max and default values. You have to be careful when defining the <code>$options</code> array, notice that its a multidimensional array.</p>
<pre name="code" class="php">

$var_1 = 73;
$var_2 = 246;

$options = array(
    'options' => array(
        'default' => 3,
        'min_range' => 0,
        'max_range' => 99,
    )
);

filter_var($var_1, FILTER_VALIDATE_INT, $options); //returns 73

filter_var($var_2, FILTER_VALIDATE_INT, $options); //returns 3
</pre>
<p>Notice that the second <code>filter_var()</code> call returned 3, this is because of the <code>default</code> value we defined in the <code>$options</code> array.</p>
<p><strong>Validating Floats</strong><br />
Validating a FLOAT work just like validating an INT does, but it uses the <code> FILTER_VALIDATE_FLOAT</code> flag instead.</p>
<pre name="code" class="php">

$var_1 = 45.3;
$var_2 = 246;

filter_var($var_1, FILTER_VALIDATE_FLOAT, $options); //returns 45.3

filter_var($var_2, FILTER_VALIDATE_FLOAT, $options); //returns 246
</pre>
<p>Note that if you pass an integer into this function with the <code> FILTER_VALIDATE_FLOAT</code> flag, it will still return it as if it was a float.</p>
<p><strong>Validating E-mail Addresses</strong><br />
You can also use this method for validating more abstract data types, such as e-mail addresses.</p>
</p>
<pre name="code" class="php">

$var_1 = "jordan@17webshop.com";

$var_2 = "some data that is obviously not an e-mail address;

filter_var($var_1, FILTER_VALIDATE_EMAIL); //returns jordan@17webshop.com

filter_var($var_2, FILTER_VALIDATE_EMAIL); //returns FALSE
</pre>
<p>However, this method isn&#8217;t quite as good as a custom regex could be. An e-mail address like a@a.a, which is obviously invalid, still passes. The following regex would be a better solution:</p>
<pre name="code" class="php">

$pattern = '/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/';

$email_1 = 'jordan@17webshop.com';

$email_2 = 'a@a.a';

preg_match($pattern, $email_1); // returns TRUE

preg_match($pattern, $email_2); //returns FALSE
</pre>
<p><strong>Validating URLs</strong></p>
<p>Validating URLs is typically pretty difficult, <code>filter_var()</code> however, does a pretty excellent job. What&#8217;s interesting about this flag is it optionally takes additional flags to facilitate better validation. Here&#8217;s a list of the additional, optional flags available:</p>
<ul>
<li><code>FILTER_FLAG_SCHEME_REQUIRED </code></li>
<li><code>FILTER_FLAG_HOST_REQUIRED </code></li>
<li><code>FILTER_FLAG_PATH_REQUIRED </code></li>
<li><code>FILTER_FLAG_QUERY_REQUIRED </code></li>
</ul>
<p>Let&#8217;s look at a few examples:</p>
<pre name="code" class="php">

$var_1 = 'http://www.17webshop.com';

$var_2 = 'http://www.17webshop.com/path/to/some/file';

$var_3 = 'http://www.17webshop.com/path/to/some/file/?foo=bar';

$var_4 = 'www.17webshop.com';

$var_5 = 'some_file.html';

$var_6 = "/path/to/some/file";

filter_var($var_1, FILTER_VALIDATE_URL); // returns http://www.17webshop.com

filter_var($var_1, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED); // returns FALSE

filter_var($var_2, FILTER_VALIDATE_URL); // returns http://www.17webshop.com/path/to/some/file

filter_var($var_2, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED); // returns FALSE

filter_var($var_3, FILTER_VALIDATE_URL); // returns http://www.17webshop.com/path/to/some/file/?foo=bar

filter_var($var_4, FILTER_VALIDATE_URL); // returns FALSE

filter_var($var_5, FILTER_VALIDATE_URL); // returns FALSE

filter_var($var_6, FILTER_VALIDATE_URL); // returns FALSE
</pre>
<p><strong>Validating IP Addresses</strong><br />
Validating IP Addresses is simple as well, and just like the <code>FILTER_VALIDATE_URL</code> flag, the <code>FILTER_VALIDATE_IP</code> flag allows a few optional flags in addition, they are listed below. You can even check ipv6 addresses.</p>
<ul>
<li><code>FILTER_FLAG_IPV4 </code></li>
<li><code>FILTER_FLAG_IPV6 </code></li>
<li><code>FILTER_FLAG_NO_PRIV_RANGE </code></li>
<li><code>FILTER_FLAG_NO_RES_RANGE </code></li>
</ul>
<pre name="code" class="php">
$var_1 = '192.168.0.1';

$var_2 = '543.152.3.9';

$var_3 = '3ffe:1900:4545:3:200:f8ff:fe21:67cf';

echo filter_var($var_1, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); // returns 192.168.0.1

echo filter_var($var_2, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); // returns FALSE

echo filter_var($var_3, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); // returns 3ffe:1900:4545:3:200:f8ff:fe21:67cf
</pre>
<p>Note that <code>543.152.3.9</code> returns false, this is because the IP address with the highest value that is still acceptable is <code>255.255.255.255</code>.</p>
<p>The <code>FILTER_FLAG_NO_PRIV_RANGE</code> and <code>FILTER_FLAG_NO_RES_RANGE</code> check to see if the address is within a private, or reserved range respectively.</p>
<h3>Useful PHP Sanitization Filters</h3>
<p><strong>Sanitizing a String</strong><br />
Sanitizing data is just as easy as validating it. Remember that <em>sanitizing</em> is different than <em>validating</em> because <em>sanitizing</em> removes unwanted characters and then returns the newly <em>validated</em> data. Let&#8217;s take a look at sanitizing some strings.</p>
<pre name="code" class="php">
$var_1 = '<tag>some string data</tag>';

$var_2 = '<tag>"some string data"</tag>';

filter_var($var_1, FILTER_SANITIZE_STRING); //returns some string data

filter_var($var_2, FILTER_SANITIZE_STRING); //returns "some string data"
</pre>
<p><strong>Sanitizing Integers</strong></p>
<pre name="code" class="php">
$var_1 = 123214;

$var_2 = '213h34bh312';

filter_var($var_1, FILTER_SANITIZE_NUMBER_INT); //returns 123214

filter_var($var_2, FILTER_SANITIZE_NUMBER_INT); //returns 21334312
</pre>
<h3>Filter Callback</h3>
<p>Maybe one of the best things about the <code>filter_var()</code> function is the <code>FILTER_CALLBACK</code> flag as it allows you define your own rule via a callback function. If you can&#8217;t find a rule that meets your needs exactly, just define one yourself with this flag.</p>
<pre name="code" class="php">
function my_rule($str) {
  return str_replace(" ", "+", $str);
}

$var_1 = "some string data with spaces in it";

$options = array(
    'options' => 'my_rule'
);

filter_var($var_1, FILTER_CALLBACK, $options); //returns some+string+data+with+spaces+in+it
</pre>
<h3>Conclusion</h3>
<p>Hopefully this post has taught you something you didn&#8217;t know about PHP, or jogged your memory on some useful functionality available to you. I didn&#8217;t go through every possible flag, for the sake of brevity, and because of the fact that while some of them are helpful and rather useful. Some of them, just&#8230; aren&#8217;t. If you want more information about these flags, take a look at the <a href="http://us3.php.net/manual/en/filter.filters.validate.php">PHP manual entry</a>.</p>
<p>As always, if you have any questions about anything discussed here. Feel free to leave them in the comments. I am always willing to help out.</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/12/10/php-filters-and-how-to-use-them/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>webshop cms, It&#8217;s Coming</title>
		<link>http://17webshop.com/2009/12/09/webshop-cms-its-coming/</link>
		<comments>http://17webshop.com/2009/12/09/webshop-cms-its-coming/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 00:08:09 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=500</guid>
		<description><![CDATA[So this is what we&#8217;ve been working on for the last month or so.
Check out webshopcms.org
More to come soon.
]]></description>
			<content:encoded><![CDATA[<p>So this is what we&#8217;ve been working on for the last month or so.</p>
<p>Check out <a href="http://webshopcms.org/">webshopcms.org</a></p>
<p>More to come soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/12/09/webshop-cms-its-coming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP From the Top: 3 (Loops and Conditions)</title>
		<link>http://17webshop.com/2009/12/08/php-from-the-top-3-loops-and-conditions/</link>
		<comments>http://17webshop.com/2009/12/08/php-from-the-top-3-loops-and-conditions/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 07:09:08 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[PHP From the Top]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[condition]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=439</guid>
		<description><![CDATA[
So it&#8217;s been some time since our last segment, today we&#8217;re going to pick up where we left off with our PHP From the Top series and jump into some new topics. Loops and Conditions are called Control Structures and are a large part of what really makes your script dynamic, they allow the script [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://17webshop.com/wp-content/uploads/2009/07/PHP-Elephant-Logo.jpg" alt="PHP Elephant Logo" title="PHP Elephant Logo" width="300" height="193" class="right" /></p>
<p>So it&#8217;s been some time since our last segment, today we&#8217;re going to pick up where we left off with our PHP From the Top series and jump into some new topics. Loops and Conditions are called Control Structures and are a large part of what really makes your script dynamic, they allow the script to somewhat make its own decisions based on current circumstances. Let&#8217;s get started.</p>
<p><span id="more-439"></span></p>
<h3>Other Posts in this Series</h3>
<ul>
<li><a href="http://17webshop.com/2009/08/07/php-from-the-top-1-getting-set-up/">1: Getting Set Up</a></li>
<li><a href="http://17webshop.com/2009/08/10/php-from-the-top-2-introduction/">2: Using Variables and Simple Math</a></li>
<li>3: Loops and Conditions </li>
</ul>
<h3>Conditions (If, Else Statements)</h3>
<p>First, we&#8217;re going to take a look at conditional statements (or If, Else statements). If and else are two seperate statements, but they often work together hand in hand. To explain how this works, I think its probably best to first draw up an example and describe it rather than keep discussing in the abstract. Here&#8217;s a simple If, Else statement.</p>
<pre name="code" class="php">
if( 1 < 2 ) {
     echo "1 is less than two";
} else {
     echo "1 is not less than two";
}
</pre>
<p>Okay, a few things to notice here: first, notice the expression in the parentheses after the if statement. This expression is what determines how the following code will be executed. If this expression evaluates to TRUE, the code in the if statement's braces will be executed. If this expression evaluates to FALSE, the code in the else statement's braces will be executed. In the above example, the script will echo "1 is less than two" because the expression <code>if( 1 < 2 )</code> will always evaluate to true. Let's take a look at a few slightly more complex examples using variables.</p>
<pre name="code" class="php">
$x = 2;
$y = 7;
if( $x > $y ) {
     echo "$x is greater than $y";
} else {
     echo "$x is not greater than $y";
}
</pre>
<p>This example will obviously evaluate to false and will echo "2 is not greater than 7".</p>
<pre name="code" class="php">
$x = 5;
$y = 10;
if( $y - $x == $x ) {
     echo "$y - $x is equal to $x";
} else {
     echo "$y - $x is not equal to $x";
}
</pre>
<p>This example shows that you can perform mathematical calculations within the conditional expression. Another important thing to note about this example is the double equal sign operator <code>==</code> in the expression. This is known as the <em>equality operator</em> and is used to determine whether or not two values are equal to one another. There are actually a few different "equal sign-like" operators in the PHP language and it's important not to confuse them. Let's take a quick look at a few of them.</p>
<style type="text/css">
th, td {text-align: left; border: 1px solid black;padding: 6px;}
</style>
<h3>Assignment and Comparison Operators</h3>
<table>
<tr>
<th>Operator</th>
<th>Description</th>
<th width="260">Example</th>
</tr>
<tr>
<td>=</td>
<td>This is the <em>assignment operator</em>. Use this "single equal sign" to assign values to variables.</td>
<td><code>$myName = 'Jordan';</code></td>
</tr>
<tr>
<td>==</td>
<td>This is the <em>equality operator</em>. Use this "double equal sign" to compare the values of two variables and determine if they are equal to each other.</td>
<td><code style="display: block;">if( 1 + 2 == 3 ) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;echo "1 + 2 = 3";<br />
}</code></td>
</tr>
<tr>
<td>===</td>
<td>This is the <em>identical comparison operator</em>. Use this "triple equal sign" to determine not only if two values are equal to one another but also to determine if both values are of the same type. In the first example to the right, both values are equal to 5 but the first variables type is <code>int</code> and the second variables type is <code>string</code> (notice the quotes). For this operator to evaluate to true both values must be equal to each other and be of the same type.</td>
<td><code style="display: block;">$int = 5;<br />
$str = '5';</p>
<p>if($int == $str) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;//evaluates to true<br />
}<br />
if($int === $str) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;//evaluates to false<br />
}</code></td>
</tr>
<tr>
<td>!=</td>
<td>This is a negation of the <em>comparison operator</em>. Use this to test if two values are not equal to one another. <small>You can also use the <code><></code> operator, however it is much more common to use <code>!=</code>.</small></td>
<td><code style="display: block;">if( 2 + 2 != 3 ) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;//evaluates to true<br />
}</code></td>
</tr>
</table>
<p>These are just a few of the operators available to you in the PHP language, if you would like to reference a full list, check out the <a href="http://php.net/manual/en/language.operators.comparison.php" target="_blank">PHP Comparison Operators page</a> at <a href="http://php.net" target="_blank">php.net</a>.</p>
<h3>Moving on to Loops</h3>
<p>Loops are an interesting control structures, a loop allows a script to repeat a block of code a defined number of times. There are a few loops that are available in PHP, but we're only going to take a look at what are probably the two most common -- "For" loops and "While" loops.</p>
<h3>While Loops</h3>
<p>A simple While Loop looks something like this:</p>
<pre name="code" class="php">
$i = 1;
while($i <= 10) {
     echo $i . "&lt;br />";
     $i++;
}
</pre>
<p>The above script will print numbers from 1 to 10 on the screen. This introduces a few new and important concepts. First of all, the use of the variable <code>$i</code>: it is a very common practice to use the variable <code>$i</code> as what's called the <em>iterator</em> when working with loops. Using this variable allows the script to keep track of how many times the loop has been executed.</p>
<p><small>NOTE: It is very important to keep track of how many times a loop has been executed and to make sure that you have a defined a maximum number of times for the loop to run. Otherwise you may end up with an <em>infinite loop</em> which will cause your script to crash.</small></p>
<p>Second you should notice the <code>++</code> operator. This is the <em>increment operator</em>. It essentially takes the variables value and adds 1 to it. In other words, <code>$i++;</code> is the same thing as <code>$i = $i + 1;</code>. It is just a shorthand. Also available with the PHP language is the opposite of the increment operator--the <em>decrement operator</em> which is simply <code>--</code>, two subtraction signs, one after the other. This operator will take the value of the variable it is assigned and subtract one from it.</p>
<p>Third, you should understand that the expression in the parentheses of the <code>while</code> statement is run exactly like the expression in the <code>if</code> statement. The loop will continue to iterate as long as the expression in the parentheses evaluates to true.</p>
<p>Now that we understand all the new syntactical points about this script we can go back and explain what happens line by line.</p>
<ul>
<li>Line 1: initialize the iterator to 1</li>
<li>Line 2: test to see if the expression is true</li>
<li>Line 3: if the expression is true we fall into the loop and evaluate the code (in this case we print the value of the iterator to the screen).</li>
<li>Line 4: we increment the iterator.</li>
</ul>
<p>After this loop has been executed 10 times, the iterator will be incremented to 11. When the expression is tested again, it will evaluate to FALSE as 11 is <strong>not</strong> greater than or equal to 10 and the script will pickup at the end of the loop and run any remaining code in the script. </p>
<h3>For Loops</h3>
<p><code>for</code> loops are much like <code>while</code> loops, except they are slightly more complex and as a result, more compact. The <code>for</code> loop expression is broken into 3 parts. Let's look at an example then break it down. I am going to write a loop that will accomplish the same thing our <code>while</code> loop example accomplished in the example above, we are just going to do it with a <code>for</code> loop instead this time.</p>
<pre name="code" class="php">
for( $i = 0 ; $i <= 10 ; $i++ ) {
     echo $i . "&lt;br />";
}
</pre>
<p>You can see how the expression of  a <code>for</code> loop is broken into 3 segments by semicolons. Let's list each of those segments and define what they do.</p>
<ul>
<li><code>$i = 0</code> This is what's called the <em>initialization expression</em>. This is the first statement that is executed when a for loop is run. Typically, the iterator variable is initialized in this expression.</li>
<li><code>$i <= 10</code> This is the <em>test expression</em>. This expression will be evaluated at the beginning of each loop cycle before the code in the braces is executed. If this expression evaluates to TRUE, the loop continues, if the expression evaluates to FALSE the loop closes.</li>
<li><code>$i++</code> This is the <em>counter</em> or <em>iterator expression</em>. It is run at the end of each loop cycle right before the test expression is tested for the next cycle. Most often, this expression simply contains an increment expression to the iterator. Just like this example shows.</li>
</ul>
<p>There are other loops that we will probably touch on later in the series. Each of them has its strengths and weaknesses, and there are times when one is more appropriate than another, but they all do about the same thing, just in a slightly different way. There are no hard and fast rules as to which you should use when.</p>
<h3>Conclusion</h3>
<p>Hopefully you have learned something through reading this post; however, I would like to stress the fact that reading about programming will only get you so far. There is no better instructor than an error log full of mistakes in your code and things gone wrong in your script. You have to sit down and write your own code and try different things on your own to get to your full potential. As always, if you have any questions or comments, please leave the in the comments. I will be happy to help you out if I can.</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/12/08/php-from-the-top-3-loops-and-conditions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Header(), Beyond Redirect</title>
		<link>http://17webshop.com/2009/12/04/php-header-beyond-redirect/</link>
		<comments>http://17webshop.com/2009/12/04/php-header-beyond-redirect/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 21:18:57 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=390</guid>
		<description><![CDATA[If you are a web developer and you&#8217;ve ever worked with PHP you have probably come across the PHP header() function in the past. You most likely used it to implement a hard redirect; but you may not have understood exactly what was happening behind the scenes every time you call this handy function. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer and you&#8217;ve ever worked with PHP you have probably come across the PHP <code>header()</code> function in the past. You most likely used it to implement a hard redirect; but you may not have understood exactly what was happening behind the scenes every time you call this handy function. Let&#8217;s take a look at what the header() function does and find some uses for it other than its most common use&#8211;redirects.</p>
<p><span id="more-390"></span></p>
<h3>What is the header() Function?</h3>
<p>The header() function is used to send raw HTTP headers to the browser or replace other ready-to-send HTTP headers. If you are unfamiliar with HTTP headers, you may find it beneficial to browse through the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" target="_blank">Header Field Definitions section of the HTTP/1.1 spec</a>.</p>
<h3>What Are HTTP Headers?</h3>
<p>HTTP headers are the foundation of HTTP (Hypertext Transfer Protocol), which the entire World Wide Web is built on. Every time you go to a webpage, just like when you came to this webpage your browser sent the server a number of header requests, and then in turn received http responses for each request. These headers contain information about the client browser, the server, and the document that the browser requested from the server.</p>
<p>Here&#8217;s an example of what some HTTP headers might look like:</p>
<style type="text/css">
div.tables td, div.tables th {padding: 4px;}
div.tables table {width: 700px;}
div.tables {background: #ddd;padding:10px;margin-bottom: 10px;}
</style>
<div class="tables">
<table cellpadding="10">
<thead>
<tr>
<th colspan="2" align="left">Response Headers</th>
</tr>
</thead>
<tbody>
<tr>
<td width="200">
			Date
			</td>
<td width="500">
			Fri, 04 Dec 2009 21:06:21 GMT
			</td>
</tr>
<tr>
<td>
			Server
			</td>
<td>
			Apache
			</td>
</tr>
<tr>
<td>
			X-Powered-By
			</td>
<td>
			PHP/5.2.9
			</td>
</tr>
<tr>
<td>
			X-Pingback
			</td>
<td>
<p>http://17webshop.com/xmlrpc.php</p>
</td>
</tr>
<tr>
<td>
			Keep-Alive
			</td>
<td>
			timeout=5, max=99
			</td>
</tr>
<tr>
<td>
			Connection
			</td>
<td>
			Keep-Alive
			</td>
</tr>
<tr>
<td>
			Transfer-Encoding
			</td>
<td>
			chunked
			</td>
</tr>
<tr>
<td>
			Content-Type
			</td>
<td>
			chunked
			</td>
</tr>
<tr>
<td>
			Server
			</td>
<td>
			text/html; charset=UTF-8
			</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th colspan="2" align="left">
			Request Headers
			</th>
</tr>
</thead>
<tbody>
<tr>
<td width="200">
			Host
			</td>
<td width="500">
			17webshop.com
			</td>
</tr>
<tr>
<td>
			User-Agent
			</td>
<td>
			Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9
			</td>
</tr>
<tr>
<td>
			Accept
			</td>
<td>
			text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
			</td>
</tr>
<tr>
<td>
			Accept-Language
			</td>
<td>
			en-us,en;q=0.5
			</td>
</tr>
<tr>
<td>
			Accept-Encoding
			</td>
<td>
			gzip,deflate
			</td>
</tr>
<tr>
<td>
			Accept-Charset
			</td>
<td>
			ISO-8859-1,utf-8;q=0.7,*;q=0.7
			</td>
</tr>
<tr>
<td>
			Keep-Alive
			</td>
<td>
			300
			</td>
</tr>
<tr>
<td>
			Connection
			</td>
<td>
			keep-alive
			</td>
</tr>
</tbody>
</table>
</div>
<h3>A Closer Look at header()</h3>
<p>In this post, I would really like to focus on uses for <code>header()</code> other than redirect, but we&#8217;ll use it as a jumping off point, since many readers will be familiar with it. When you call <code>header()</code> to implement a redirect, your call will be something similar to this:</p>
<pre name="code" class="php">
	header( 'Location: http://www.mysite.com/path/to/redirected/page/index.php' );
	exit();
</pre>
<p>What is actually happening when you run the code above is you are sending a &#8220;Location&#8221; response header to the browser (along with a 302 status code) with a value of &#8220;http://www.mysite.com/path/to/redirected/page/index.php&#8221;</p>
<p><small>A quick aside: I have noticed many coders do not include a call to <code>exit()</code> after <code>header()</code> is called. This isn&#8217;t necessary, but it <em>is</em> considered a best practice. In the event that your redirect fails, you will more than likely want to keep the rest of the script from executing. Additionally, another note: The HTTP/1.1 spec requires that the value for the &#8220;Location&#8221; header be an absolute URI (i.e: contains scheme, hostname, and path). While many environments will accept a relative URI, I would recommend that you use an absolute URI for maximum script portability and adherence to the specification.</small></p>
<h3>A Few Additional Uses for header()</h3>
<p>Let&#8217;s take a look now at a few fun/useful headers we can send.</p>
<p><strong>Status Codes</strong></p>
<pre name="code" class="php">
	  header('HTTP/1.1 200 OK');
</pre>
<p>You can send raw status codes to the browser by using the method above. This can be useful if you are using a php script as a landing for your 404 NOT FOUND errors, and you want to replace the previously sent 404 NOT FOUND status code to a fresh 200 OK.</p>
<p><strong>Content-Type:</strong></p>
<pre name="code" class="php">
	  header('Content-Type: application/pdf');
</pre>
<p>The Content-Type header is used to define the mime-type of a document. This helps the browser know how to interpret the data it receives so that you can view it in its intended form. For example, an image file is displayed differently than an HTML file. The header above would indicate a PDF document.</p>
<p><strong>Content-Disposition:</strong></p>
<pre name="code" class="php">
	 header('Content-Type: application/zip');
	 header('Content-Disposition: attachment; filename="downloadMe.zip"');
</pre>
<p>Send the Content-Disposition header if you would like to prompt the user to download a file, such as an image, an excel spreadsheet, or a PDF (which you should define with the previously mentioned &#8220;Content-Type&#8221; header). The prompt will be similar to the one shown below:</p>
<p><img src="/wp-content/uploads/2009/12/Picture-1.png" alt="Download Prompt" /></p>
<p><strong>Content-Length:</strong></p>
<pre name="code" class="php">
	 header('Content-Type: application/zip');
	 header('Content-Length: 38724');
	 header('Content-Disposition: attachment; filename="downloadMe.zip"');
</pre>
<p>Content-Length is another header that should be used when prompting a user to download a file. This header defines the size of the file to be downloaded (in bytes) and is used by browsers when downloading files to tell the user how much of the download has completed. Have you ever noticed how sometimes your browser&#8217;s download manager will tell you how far a file download has progressed (something like &#8220;43% Complete&#8221;), and sometimes it will only say something to the effect of &#8220;458kb of ? have been transfered.&#8221; The culprit in this scenario is developers neglecting the implementation of the Content-Length header. In my opinion is a simple courtesy to include this header in your scripts involving file downloads.</p>
<p><strong>Cache-Control:</strong></p>
<pre name="code" class="php">
	  header('Cache-Control: max-age=3600, public');
</pre>
<p>The Cache-Control header is used to define rules for caching the document it relates to or resides in. You can enabled, disable or limit caching by using a number of directives such as <code>public</code> to enabled caching by anyone, or <code>no-cache</code> to disable caching for everyone. More info on these directives and more can be found <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9" target="_blank">here</a>.</p>
<h3>Conclusion</h3>
<p>Hopefully, you have discovered a few new things about HTTP headers and what you can do with PHP&#8217;s <code>header()</code> function. Remember, headers must be sent before any other output, so make sure to place them at the top of your script or before any html tags or whitespace. This includes anything included via <code>include()</code>, <code>require()</code>, <code>include_once()</code>, and<code> require_once()</code>. Even a space will throw an error.</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/12/04/php-header-beyond-redirect/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>17 Webshop Hires Graphic Designer Jacob Cowdin</title>
		<link>http://17webshop.com/2009/11/20/17-webshop-hires-graphic-designer-jacob-cowdin/</link>
		<comments>http://17webshop.com/2009/11/20/17-webshop-hires-graphic-designer-jacob-cowdin/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 20:36:10 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=363</guid>
		<description><![CDATA[I wanted to take a moment to recognize that we have just taken on a new partner. Jacob Cowdin is a graphic designer living in Denton, Tx. He graduated from Oklahoma Christian in 2008 with a degree in Graphic Design and after spending some time in Portland, Or has found himself in Denton. We are [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to take a moment to recognize that we have just taken on a new partner. Jacob Cowdin is a graphic designer living in Denton, Tx. He graduated from Oklahoma Christian in 2008 with a degree in Graphic Design and after spending some time in Portland, Or has found himself in Denton. We are really excited that Jacob has joined out team!</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/11/20/17-webshop-hires-graphic-designer-jacob-cowdin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding Variable Scope</title>
		<link>http://17webshop.com/2009/08/19/understanding-variable-scope/</link>
		<comments>http://17webshop.com/2009/08/19/understanding-variable-scope/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 03:31:16 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[global scope]]></category>
		<category><![CDATA[local scope]]></category>
		<category><![CDATA[static variables]]></category>
		<category><![CDATA[variable scope]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=299</guid>
		<description><![CDATA[I&#8217;m going to deviate from the PHP From the Top series I&#8217;ve been writing from time to time to address a few other programming/scripting concepts. Today we&#8217;ll be discussing variable scope, what it is, and how to use it. If you have been following along with the PHP From the Top Series, some of this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to deviate from the PHP From the Top series I&#8217;ve been writing from time to time to address a few other programming/scripting concepts. Today we&#8217;ll be discussing variable scope, what it is, and how to use it. If you have been following along with the PHP From the Top Series, some of this may be over your head at this point, and that&#8217;s okay. If you have questions, feel free to ask them in the comments. We will cover these concepts again later in the series. Much of this article will apply to many different languages; however, I will be using PHP to illustrate these concepts in this article.</p>
<h3>What is Variable Scope</h3>
<p>Variable scope refers to the context in which a variable is defined or the setting in which it is available for use. Whenever a variable is declared, it is declared in a particular scope. In PHP, there are two different possible scopes, <code>global</code> and <code>local</code>.</p>
<p><span id="more-299"></span></p>
<p>When you declare a variable in PHP like this:</p>
<pre name="code" class="php">
	$count = 5; //$count is defined in the global scope
</pre>
<p>The variable is declared in the <code>global</code> scope. This means that the variable is available to interact with and be used and manipulated by other processes in the <code>global</code> scope. Variables declared in the <code>global</code> scope cannot be used in the <code>local</code> scope and the other way around. Let&#8217;s look at what it means to define something in the <code>local</code> scope.</p>
<pre name="code" class="php">
function full_name($first_name, $last_name) {

	$full_name = $first_name.$last_name;

	return($full_name); //$full_name is declared in the local scope
}
</pre>
<h3>Determining Which Scope You&#8217;re Using</h3>
<p>Variables that are defined in the local scope cannot interact with variables in the global scope. You could even have two variables of the same name, in either scope and they could hold two different values. For example:</p>
<pre name="code" class="php">
function do_something() {

	$variable = 2; //local scope

}

$variable = 5; //global scope

echo $variable; //echoes 5

do_something();

echo $variable; //still echoes 5
</pre>
<p>Within the function <code>do_something()</code>, the value of <code>$variable</code> was set to 2. However, it was set in the <code>local</code> scope. The <code>echo</code> statement, however, was used in the <code>global</code> scope. Therefore, the instance of <code>$variable</code> that was set to 2 was never accessed or used. Essentially, when a variable is defined within a function, that variable only exists within that function. Once the function is executed and completed, the variable is no longer accessible and cannot be used.</p>
<h3>Working Around Variable Scope</h3>
<p>So if we can&#8217;t access a global variable inside a function how to we get access to those values? Well there are a couple of ways to do this. The first way is to pass variables into functions as <em>arguments</em>. Passing a global variable as an argument allows the variables value to be altered in the local scope by effectively making a copy of the variable and pasting it into the new scope. But will the value still be altered in the global scope? No it won&#8217;t. This is because we are only creating a copy of the variable. However, we can still retrieve the new value by <em>returning</em> the variable when we are done. Let&#8217;s look at an example:</p>
<pre name="code" class="php">

$var = 40;

function divide_by_two($var) {
	return($var / 2);
}

echo $var; //echoes 40

$var = divide_by_two($var);

echo $var; //echoes 20
</pre>
<p>This method, however, can get to be a bit cumbersome when working with large amounts of variables. Passing in all of these variables as arguments can get messy, and PHP functions can only return one variable at a time. You would therefore need to call functions multiple times. Is there an easier way? Yes there is. We can use the <code>global</code> keyword to bring global variables into the local scope. Say you have a variable that stores a path to a upload folder for your application.</p>
<pre name="code" class="php">

$upload_path = '/path/to/uploads/directory/';

function delete_uploaded_file($filename) {

	//bring the variable $var out of the global scope and into
	//the local scope so it can be accessed and altered.

	global $upload_path;

	if(file_exists($upload_path.$filename)) {
		unlink($upload_path.$filename);
	}
}

delete_uploaded_file('image.jpg');
</pre>
<p>This can also be done by using the superglobal associative array <code>$GLOBALS</code>:</p>
<pre name="code" class="php">

$upload_path = '/path/to/uploads/directory/';

function delete_uploaded_file($filename) {

	if(file_exists($GLOBALS['upload_path'].$filename)) {
		unlink($GLOBALS['upload_path'].$filename);
	}
}

delete_uploaded_file('image.jpg');
</pre>
<h3>Using Static Variables</h3>
<p><code>Static</code> variables can occasionally come in handy as well, and are a good thing to know about when the need comes up. A <code>static</code> variable only exists in the local scope. However, the value of the variable remains there even when the parser leaves the local scope.</p>
<pre name="code" class="php">
	function show_last_count() {
		//$count is declared as static and the value will remain after the function as been called.
		static $count = 0;
		echo $count;
		$count++;
	}
	show_last_count(); //echos 0
	show_last_count(); //echos 1
	show_last_count(); //echos 2
	show_last_count(); //echos 3
</pre>
<p>NOTE: when assigning values to static variables you must assign them as listed in the example above&#8211;that is as a straight value, not as the result of an expression. Assigning the result of an expression as static will throw in a parse error.</p>
<pre name="code" class="php">
	function do_something() {
		static $static_var = 1 + 1; //throws a parse error.
	}
</pre>
<h3>Conclusion</h3>
<p>Understanding scope is a crucial concept in programming, and lack of understanding it can lead to writing some incredibly messy and difficult to maintain code. However, that doesn&#8217;t mean that you should always use the methods defined here. I&#8217;ve listed a few options for you, use the one that makes the most sense to you. If it makes sense to pass a variable into a function as an argument, perhaps because that value is constantly changing, do it that way. It is okay to work within where you&#8217;re comfortable. But that doesn&#8217;t mean you shouldn&#8217;t be aware of what your other options are.</p>
<p>If you have any questions, if I didn&#8217;t explain something as clear as you would have liked, please don&#8217;t hesitate to let me know. Leave a comment on this article. Someone will be thrilled to help you out.</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/08/19/understanding-variable-scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reserved Words in the SQL Language</title>
		<link>http://17webshop.com/2009/08/19/reserved-words-in-the-sql-language/</link>
		<comments>http://17webshop.com/2009/08/19/reserved-words-in-the-sql-language/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 01:49:08 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[Cheat Sheets]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[sql error]]></category>
		<category><![CDATA[writing sql queries]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=309</guid>
		<description><![CDATA[
When writing SQL queries and naming columns while building your database, you have to be careful which words you use.  Some words are reserved by the SQL language for use as special built in commands and functions. Using these words as a column identifier, for example, will throw an SQL error and your query [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://17webshop.com/wp-content/uploads/2009/08/mysql1.png" alt="mysql1" title="mysql1" width="300" class="right size-full wp-image-310" /></p>
<p>When writing SQL queries and naming columns while building your database, you have to be careful which words you use.  Some words are reserved by the SQL language for use as special built in commands and functions. Using these words as a column identifier, for example, will throw an SQL error and your query will die. I have found myself many many times pulling my hair out over a particular query, trying to find out why it isn&#8217;t working only to later discover that I named one of my columns with a reserved word. Some of these reserved words include <code>SELECT</code>, <code>UPDATE</code> and <code>WHERE</code>. Those you were probably already familiar with if you have ever written any SQL queries; the full list, however, is actually pretty lengthy and contains many commands you may not have known about. Additionally, as you browse this list, take a moment to look up the commands you aren&#8217;t familiar with. This can help you learn about some previously unknown and powerful features of the language.</p>
<p><span id="more-309"></span></p>
<p>It should be noted, however, that reserved words can actually be used in queries outside of their special uses if you quote them. For example:</p>
<pre name="code" class="sql">
SELECT * FROM messages WHERE read=0 LIMIT 10; //bad
SELECT * FROM messages WHERE `read`=0 LIMIT 10; //good
</pre>
<p>The word &#8220;read&#8221; is a reserved word, and can only be used as the identifier for a column if it is quoted.</p>
<p>To help you avoid the mistakes I&#8217;ve made and stress I&#8217;ve suffered. I&#8217;ve compiled (what I think to be) a complete list of these reserved words to reference as a sort of cheat sheet in the future when frustrating queries, that you <strong>know</strong> are correct, just don&#8217;t seem to work.</p>
<h3>Reserved Words in SQL</h3>
<table cellspacing="4">
<tbody>
<tr>
<td><code>ACCESSIBLE</code></td>
<td><code>ADD</code></td>
<td><code>ALL</code></td>
<td><code>ALTER</code></td>
</tr>
<tr>
<td><code>ANALYZE</code></td>
<td><code>AND</code></td>
<td><code>AS</code></td>
<td><code>ASC</code></td>
</tr>
<tr>
<td><code>ASENSITIVE</code></td>
<td><code>BEFORE</code></td>
<td><code>BETWEEN</code></td>
<td><code>BIGINT</code></td>
</tr>
<tr>
<td><code>BINARY</code></td>
<td><code>BLOB</code></td>
<td><code>BOTH</code></td>
<td><code>BY</code></td>
</tr>
<tr>
<td><code>CALL</code></td>
<td><code>CASCADE</code></td>
<td><code>CASE</code></td>
<td><code>CHANGE</code></td>
</tr>
<tr>
<td><code>CHAR</code></td>
<td><code>CHARACTER</code></td>
<td><code>CHECK</code></td>
<td><code>COLLATE</code></td>
</tr>
<tr>
<td><code>COLUMN</code></td>
<td><code>CONDITION</code></td>
<td><code>CONSTRAINT</code></td>
<td><code>CONTINUE</code></td>
</tr>
<tr>
<td><code>CONVERT</code></td>
<td><code>CREATE</code></td>
<td><code>CROSS</code></td>
<td><code>CURRENT_DATE</code></td>
</tr>
<tr>
<td><code>CURRENT_TIME</code></td>
<td><code>CURRENT_TIMESTAMP</code></td>
<td><code>CURRENT_USER</code></td>
<td><code>CURSOR</code></td>
</tr>
<tr>
<td><code>DATABASE</code></td>
<td><code>DATABASES</code></td>
<td><code>DAY_HOUR</code></td>
<td><code>DAY_MICROSECOND</code></td>
</tr>
<tr>
<td><code>DAY_MINUTE</code></td>
<td><code>DAY_SECOND</code></td>
<td><code>DEC</code></td>
<td><code>DECIMAL</code></td>
</tr>
<tr>
<td><code>DECLARE</code></td>
<td><code>DEFAULT</code></td>
<td><code>DELAYED</code></td>
<td><code>DELETE</code></td>
</tr>
<tr>
<td><code>DESC</code></td>
<td><code>DESCRIBE</code></td>
<td><code>DETERMINISTIC</code></td>
<td><code>DISTINCT</code></td>
</tr>
<tr>
<td><code>DISTINCTROW</code></td>
<td><code>DIV</code></td>
<td><code>DOUBLE</code></td>
<td><code>DROP</code></td>
</tr>
<tr>
<td><code>DUAL</code></td>
<td><code>EACH</code></td>
<td><code>ELSE</code></td>
<td><code>ELSEIF</code></td>
</tr>
<tr>
<td><code>ENCLOSED</code></td>
<td><code>ESCAPED</code></td>
<td><code>EXISTS</code></td>
<td><code>EXIT</code></td>
</tr>
<tr>
<td><code>EXPLAIN</code></td>
<td><code>FALSE</code></td>
<td><code>FETCH</code></td>
<td><code>FLOAT</code></td>
</tr>
<tr>
<td><code>FLOAT4</code></td>
<td><code>FLOAT8</code></td>
<td><code>FOR</code></td>
<td><code>FORCE</code></td>
</tr>
<tr>
<td><code>FOREIGN</code></td>
<td><code>FROM</code></td>
<td><code>FULLTEXT</code></td>
<td><code>GRANT</code></td>
</tr>
<tr>
<td><code>GROUP</code></td>
<td><code>HAVING</code></td>
<td><code>HIGH_PRIORITY</code></td>
<td><code>HOUR_MICROSECOND</code></td>
</tr>
<tr>
<td><code>HOUR_MINUTE</code></td>
<td><code>HOUR_SECOND</code></td>
<td><code>IF</code></td>
<td><code>IGNORE</code></td>
</tr>
<tr>
<td><code>IN</code></td>
<td><code>INDEX</code></td>
<td><code>INFILE</code></td>
<td><code>INNER</code></td>
</tr>
<tr>
<td><code>INOUT</code></td>
<td><code>INSENSITIVE</code></td>
<td><code>INSERT</code></td>
<td><code>INT</code></td>
</tr>
<tr>
<td><code>INT1</code></td>
<td><code>INT2</code></td>
<td><code>INT3</code></td>
<td><code>INT4</code></td>
</tr>
<tr>
<td><code>INT8</code></td>
<td><code>INTEGER</code></td>
<td><code>INTERVAL</code></td>
<td><code>INTO</code></td>
</tr>
<tr>
<td><code>IS</code></td>
<td><code>ITERATE</code></td>
<td><code>JOIN</code></td>
<td><code>KEY</code></td>
</tr>
<tr>
<td><code>KEYS</code></td>
<td><code>KILL</code></td>
<td><code>LEADING</code></td>
<td><code>LEAVE</code></td>
</tr>
<tr>
<td><code>LEFT</code></td>
<td><code>LIKE</code></td>
<td><code>LIMIT</code></td>
<td><code>LINEAR</code></td>
</tr>
<tr>
<td><code>LINES</code></td>
<td><code>LOAD</code></td>
<td><code>LOCALTIME</code></td>
<td><code>LOCALTIMESTAMP</code></td>
</tr>
<tr>
<td><code>LOCK</code></td>
<td><code>LONG</code></td>
<td><code>LONGBLOB</code></td>
<td><code>LONGTEXT</code></td>
</tr>
<tr>
<td><code>LOOP</code></td>
<td><code>LOW_PRIORITY</code></td>
<td><code>MASTER_SSL_VERIFY_SERVER_CERT</code></td>
<td><code>MATCH</code></td>
</tr>
<tr>
<td><code>MEDIUMBLOB</code></td>
<td><code>MEDIUMINT</code></td>
<td><code>MEDIUMTEXT</code></td>
<td><code>MIDDLEINT</code></td>
</tr>
<tr>
<td><code>MINUTE_MICROSECOND</code></td>
<td><code>MINUTE_SECOND</code></td>
<td><code>MOD</code></td>
<td><code>MODIFIES</code></td>
</tr>
<tr>
<td><code>NATURAL</code></td>
<td><code>NOT</code></td>
<td><code>NO_WRITE_TO_BINLOG</code></td>
<td><code>NULL</code></td>
</tr>
<tr>
<td><code>NUMERIC</code></td>
<td><code>ON</code></td>
<td><code>OPTIMIZE</code></td>
<td><code>OPTION</code></td>
</tr>
<tr>
<td><code>OPTIONALLY</code></td>
<td><code>OR</code></td>
<td><code>ORDER</code></td>
<td><code>OUT</code></td>
</tr>
<tr>
<td><code>OUTER</code></td>
<td><code>OUTFILE</code></td>
<td><code>PRECISION</code></td>
<td><code>PRIMARY</code></td>
</tr>
<tr>
<td><code>PROCEDURE</code></td>
<td><code>PURGE</code></td>
<td><code>RANGE</code></td>
<td><code>READ</code></td>
</tr>
<tr>
<td><code>READS</code></td>
<td><code>READ_WRITE</code></td>
<td><code>REAL</code></td>
<td><code>REFERENCES</code></td>
</tr>
<tr>
<td><code>REGEXP</code></td>
<td><code>RELEASE</code></td>
<td><code>RENAME</code></td>
<td><code>REPEAT</code></td>
</tr>
<tr>
<td><code>REPLACE</code></td>
<td><code>REQUIRE</code></td>
<td><code>RESTRICT</code></td>
<td><code>RETURN</code></td>
</tr>
<tr>
<td><code>REVOKE</code></td>
<td><code>RIGHT</code></td>
<td><code>RLIKE</code></td>
<td><code>SCHEMA</code></td>
</tr>
<tr>
<td><code>SCHEMAS</code></td>
<td><code>SECOND_MICROSECOND</code></td>
<td><code>SELECT</code></td>
<td><code>SENSITIVE</code></td>
</tr>
<tr>
<td><code>SEPARATOR</code></td>
<td><code>SET</code></td>
<td><code>SHOW</code></td>
<td><code>SMALLINT</code></td>
</tr>
<tr>
<td><code>SPATIAL</code></td>
<td><code>SPECIFIC</code></td>
<td><code>SQL</code></td>
<td><code>SQLEXCEPTION</code></td>
</tr>
<tr>
<td><code>SQLSTATE</code></td>
<td><code>SQLWARNING</code></td>
<td><code>SQL_BIG_RESULT</code></td>
<td><code>SQL_CALC_FOUND_ROWS</code></td>
</tr>
<tr>
<td><code>SQL_SMALL_RESULT</code></td>
<td><code>SSL</code></td>
<td><code>STARTING</code></td>
<td><code>STRAIGHT_JOIN</code></td>
</tr>
<tr>
<td><code>TABLE</code></td>
<td><code>TERMINATED</code></td>
<td><code>THEN</code></td>
<td><code>TINYBLOB</code></td>
</tr>
<tr>
<td><code>TINYINT</code></td>
<td><code>TINYTEXT</code></td>
<td><code>TO</code></td>
<td><code>TRAILING</code></td>
</tr>
<tr>
<td><code>TRIGGER</code></td>
<td><code>TRUE</code></td>
<td><code>UNDO</code></td>
<td><code>UNION</code></td>
</tr>
<tr>
<td><code>UNIQUE</code></td>
<td><code>UNLOCK</code></td>
<td><code>UNSIGNED</code></td>
<td><code>UPDATE</code></td>
</tr>
<tr>
<td><code>USAGE</code></td>
<td><code>USE</code></td>
<td><code>USING</code></td>
<td><code>UTC_DATE</code></td>
</tr>
<tr>
<td><code>UTC_TIME</code></td>
<td><code>UTC_TIMESTAMP</code></td>
<td><code>VALUES</code></td>
<td><code>VARBINARY</code></td>
</tr>
<tr>
<td><code>VARCHAR</code></td>
<td><code>VARCHARACTER</code></td>
<td><code>VARYING</code></td>
<td><code>WHEN</code></td>
</tr>
<tr>
<td><code>WHERE</code></td>
<td><code>WHILE</code></td>
<td><code>WITH</code></td>
<td><code>WRITE</code></td>
</tr>
<tr>
<td><code>XOR</code></td>
<td><code>YEAR_MONTH</code></td>
<td><code>ZEROFILL</code></td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/08/19/reserved-words-in-the-sql-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>17 Webshop is Hiring!</title>
		<link>http://17webshop.com/2009/08/17/17-webshop-is-hiring/</link>
		<comments>http://17webshop.com/2009/08/17/17-webshop-is-hiring/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 20:33:53 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=296</guid>
		<description><![CDATA[I&#8217;m going to keep this short: 17 Webshop is hiring! We&#8217;re looking for a new graphic designer to join our team, a few requirements:

must have examples of previous work
must be knowledgeable about design concepts, composition, color theory, typography, etc
should have at least a basic understanding of (x)HTML and CSS, how they work, and how to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to keep this short: 17 Webshop is hiring! We&#8217;re looking for a new graphic designer to join our team, a few requirements:</p>
<ul>
<li>must have examples of previous work</li>
<li>must be knowledgeable about design concepts, composition, color theory, typography, etc</li>
<li>should have at least a basic understanding of (x)HTML and CSS, how they work, and how to use them.</li>
<li>must be comfortable using Adobe Photoshop and Illustrator (or equivalent) and be comfortable working with raster <em>and</em> vector images.</li>
<li>must be local to the DFW metroplex, preferably Denton, and preferably a student.</li>
</ul>
<p>Hours are extremely flexible, will work with your schedule. Will discuss rates upon interview.</p>
<p>If you are interested, please send an email to Jordan: <a href="mailto:&#106;&#111;&#114;&#100;&#97;&#110;&#64;&#49;&#55;&#119;&#101;&#98;&#115;&#104;&#111;&#112;&#46;&#99;&#111;&#109;">&#106;&#111;&#114;&#100;&#97;&#110;&#64;&#49;&#55;&#119;&#101;&#98;&#115;&#104;&#111;&#112;&#46;&#99;&#111;&#109;</a> with a link to a portfolio, or an attached pdf (please dont send .psd or .ai files), a little bit about yourself and your experience.</p>
<p>Thanks so much!</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/08/17/17-webshop-is-hiring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP From the Top: 2 (Using Variables and Simple Math)</title>
		<link>http://17webshop.com/2009/08/10/php-from-the-top-2-introduction/</link>
		<comments>http://17webshop.com/2009/08/10/php-from-the-top-2-introduction/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 17:54:18 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[PHP From the Top]]></category>
		<category><![CDATA[development environment]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php code]]></category>
		<category><![CDATA[php development]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=207</guid>
		<description><![CDATA[
This is the second installment of this new series I&#8217;m writing called &#8220;PHP From the Top.&#8221; Hopefully this guide will become a resource for beginners to get a handle on the PHP language and how to use it. I&#8217;m going to do my absolute best to not gloss over little details as I&#8217;ve found that [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://17webshop.com/wp-content/uploads/2009/07/PHP-Elephant-Logo.jpg" alt="PHP Elephant Logo" title="PHP Elephant Logo" width="300" height="193" class="right" /></p>
<p>This is the second installment of this new series I&#8217;m writing called &#8220;PHP From the Top.&#8221; Hopefully this guide will become a resource for beginners to get a handle on the PHP language and how to use it. I&#8217;m going to do my absolute best to not gloss over little details as I&#8217;ve found that many times beginners simply over look something minute yet crucial, get frustrated and the give up. I want to do my best to avoid this, and if any readers come across anything of the like, please feel free to discuss it in the comments. Anyway, today we&#8217;re going to cover the basics of the PHP language and get our hands dirty with a little bit of code for the first time.</p>
<p><span id="more-207"></span></p>
<p>If you&#8217;re new to the PHP language you may want to read <a href="http://17webshop.com/2009/08/07/php-from-the-top-1-getting-set-up/">the first article in this series</a> on how to get set up with a PHP development environment on your machine. But, if you&#8217;re already set up and ready to go, we&#8217;re going to dive in.</p>
<p>NOTE: I will assume you know HTML and CSS in that I wont go over those elements used as supplements to these articles, however if you do not know HTML and CSS it should not be detrimental to your understanding of the concepts outlined here.</p>
<h3>Other Posts in this Series</h3>
<ul>
<li><a href="http://17webshop.com/2009/08/07/php-from-the-top-1-getting-set-up/">1: Getting Set Up</a></li>
<li>2: Using Variables and Simple Math</li>
<li><a href="http://17webshop.com/2009/12/08/php-from-the-top-3-loops-and-conditions/">3: Loops and Conditions</a></li>
</ul>
<h3>Getting Started</h3>
<p>First of all, PHP&#8217;s opening and closing tags look like this: <code>&lt;?php</code> and <code>?></code>. This is very similar to a how an HTML tag works, you write your code between the two tags like the example below:</p>
<pre name="code" class="php">
&lt;?php
	//This is where you write your PHP code.
?>
</pre>
<p>Anytime you write PHP code, it must be between these two tags. For the rest of this article and this series, I will omit the opening and closing <code>&lt;?php</code> and <code>?></code> tags from the code examples. Just remember that they must be there for your code to properly execute.</p>
<h3>Printing a Message</h3>
<p>In PHP there are two ways to print data to the screen. <code>echo</code> and <code>print</code>. Technically, you can use whichever one you wish, there are arguments for both sides which I won&#8217;t get into now (maybe in another article), but I will use <code>echo</code> throughout this article and throughout this series.</p>
<p>Printing output to the screen in PHP is extremely simple and easy all you have to do is write:</p>
<pre name="code" class="php">
	echo "Print this message to the screen.";
</pre>
<p>Now there are a few things here I want you to notice and understand with this line of code. First, the message is enclosed in quotation marks. You may use double or single quotation marks, there are pros and cons to using either one of them, just make sure you stay consistent. Second, the line ends in a semicolon <code>;</code>. Every line of PHP code you write must end in a semicolon. This tells the parser that this is the end of a line (the end of a command) and now it can move on to the next one. This is because PHP is whitespace insensitive, and doesnt care if you add spaces, line breaks, or tabs within your code. Ultimately, any whitespace, unless encapsulated with quotation marks, will be ignored.</p>
<h3>Commenting Your Code</h3>
<p>While programming you may want to leave a note in your code, perhaps to yourself or to someone else that may look at your code in the future. This can be done by using comments. Comments are ignored by the parser and therefore only show up in the code. You can comment out a line, a few lines, or whole blocks of code. In PHP, comments are declared using two methods, if you only want to comment out one line, precede the text you want commented with two forward slashes <code>//</code>, if you want to comment out more than one line you add a forward slash followed by an asterisk <code>/*</code> to the beginning of the comment, and an asterisk followed by a forward slash <code>*/</code>at the end of the comment.</p>
<pre name="code" class="php">
	//This is a single line comment. This whole line will be ignored.

	/*This is a multiple line comment

	All of these
	lines will
	be ignored*/
</pre>
<p>It is generally considered good practice to leave comments in your code, this enhances code readability. It will help others navigate and understand your code more quickly and it will help you not forget why you did something a certain way. I will use comments in the example code throughout this series for code explanation.</p>
<h3>Executing Your Code</h3>
<p>PHP code can be written right next to your HTML code in the same file, and the other way around, you just have to remember that if you&#8217;re using PHP code in a file you have to change the filename to <code>.php</code> instead of <code>.html</code>. (If you write PHP code in a <code>.html</code> file, it will simply be ignored.) This is fundamentally important. You have to remember that PHP is a <strong>Server-side</strong> scripting language, this means that the code is actually executed before it reaches your user&#8217;s web browser. This is important to understand because when your PHP code outputs a message, that message is printed to the HTML file that your users will view in their browsers. You can actually have PHP output HTML tags to the browser. You can do it like this:</p>
<pre name="code" class="php">
	echo "&lt;strong>This text will be bold&lt;/strong>";
</pre>
<h3>Simple Math in PHP</h3>
<p>Performing mathematical calculations in PHP is very easy, and the operators may already be familiar to you if you have ever had to do math on a computer. Let&#8217;s take a look at an example.</p>
<pre name="code" class="php">
	echo 1 + 1; //prints the number "2"
</pre>
<p> Let&#8217;s look at some of the operators we can use.</p>
<pre name="code" class="php">
	echo 3 + 2; //Addition, prints the number "5"
	echo 3 - 2; //Subtraction, prints the number "1"
	echo 3 * 2; //Multiplication, prints the number "6"
	echo 3 / 2; //Division, prints the number "1.5"
	echo 3 % 2; //Modulus or Remainder Operator, prints the number "1"
</pre>
<p>Note that PHP does follow the traditional mathematical order of operations. If you want to alter the order in with your calculation is performed, use parentheses.</p>
<pre name="code" class="php">
	echo 3 + 2 * 4; //prints 11
	echo (3 + 2) * 4; //prints 20
</pre>
<h3>Using Variables</h3>
<p>In PHP, variables are defined by preceding the name of the variable with a dollar sign: <code>$</code>. Variable names may only contain alphanumeric characters or underscores, they must start with a lowercase alphabetic character, and may not contain spaces. PHP is a dynamically typed language, which means that you do not need to declare variable types, you simple declare the variable name and its value. A variable can be assigned many different values types: integer (a whole number), float (a decimal number), string (text) and a few others that we&#8217;ll get into later on in this series. Let&#8217;s look at a few examples of assigning different data types to variables.</p>
<pre name="code" class="php">
	$int = 4; //this variable holds 4
	$float = 1.5; //this variable holds 1.5
	$string = "This is a string."; //this variable holds "This is a string."
</pre>
<p>You can perform math with variables, just as you would expect (as long as the variables contain number values).</p>
<pre name="code" class="php">
	$int1 = 5;
	$int2 = 7;

	echo $int1 + $int2; //outputs 12

	$int3 = $int1 + $int2;

	echo $int3; //also outputs 12
</pre>
<h3>Putting it All Together</h3>
<p>I know this article got a bit lengthy, its a lot of information to take in at one sitting. Read through it again, and really take your time to make sure you understand it. This is the foundation of understanding the PHP language. Now that you know how to declare a php code block, how to output data to the screen, how to comment your code, how to perform simple math and use variables you are able to build simple PHP scripts from scratch. Take some time to play with these concepts in your own applications. If you have any questions about anything discussed in this article or anything else regarding PHP, feel free to ask them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/08/10/php-from-the-top-2-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP From The Top: 1 (Getting Set Up)</title>
		<link>http://17webshop.com/2009/08/07/php-from-the-top-1-getting-set-up/</link>
		<comments>http://17webshop.com/2009/08/07/php-from-the-top-1-getting-set-up/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 06:37:35 +0000</pubDate>
		<dc:creator>Jordan Stephens</dc:creator>
				<category><![CDATA[PHP From the Top]]></category>
		<category><![CDATA[dynamic web pages]]></category>
		<category><![CDATA[hypertext preprocessor]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[oop concepts]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[scripting language]]></category>
		<category><![CDATA[server side language]]></category>
		<category><![CDATA[web developer]]></category>

		<guid isPermaLink="false">http://17webshop.com/?p=126</guid>
		<description><![CDATA[
This is going to be the first article in this &#8220;PHP From The Top&#8221; series that I am going to be writing. I will be covering PHP basics, all the way up to some OOP concepts and applications, and hopefully some more advanced topics as time goes on. I figured today we would begin with [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://17webshop.com/wp-content/uploads/2009/07/PHP-Elephant-Logo.jpg" alt="PHP Elephant Logo" title="PHP Elephant Logo" width="300" height="193" class="right" /></p>
<p>This is going to be the first article in this &#8220;PHP From The Top&#8221; series that I am going to be writing. I will be covering PHP basics, all the way up to some OOP concepts and applications, and hopefully some more advanced topics as time goes on. I figured today we would begin with a bit of a primer into what PHP is and what it is used for. This series will assume that you atleast have a basic understanding of (x)HTML and CSS (CSS used will not be crucial in most cases and will therefor not be focused on). Let&#8217;s get started!</p>
<p><span id="more-126"></span></p>
<h3>Other Posts in this Series</h3>
<ul>
<li>1: Getting Set Up</li>
<li><a href="http://17webshop.com/2009/08/10/php-from-the-top-2-introduction/">2: Using Variables and Simple Math</a></li>
<li><a href="http://17webshop.com/2009/12/08/php-from-the-top-3-loops-and-conditions/">3: Loops and Conditions</a></li>
</ul>
<h3>Introduction</h3>
<p>PHP is a scripting language most often used for programming on the web and the development of dynamic web pages and applications. It is a server-side language (which means that the code is executed on the server before it is sent to the user&#8217;s browser), this is in contrast with other scripting languages such as Javascript which are actually executed on the user&#8217;s browser <em>after the page is loaded</em>. PHP is executed before the page loads.</p>
<h3>Behind the Name &#8220;PHP&#8221;</h3>
<p>The acronym &#8220;PHP&#8221; originally stood for &#8220;Personal Home Page,&#8221; but as the web has evolved the meaning of the name has since changed. &#8220;PHP&#8221; now stands for &#8220;PHP: Hypertext Preprocessor,&#8221; which actually is quite odd in and of itself as the acronym is recursive&#8211;that is, the first &#8220;P&#8221; in &#8220;PHP&#8221; actually stands for &#8220;PHP&#8221; and the first &#8220;P&#8221; in that second instance of &#8220;PHP&#8221; also stands for another instance of the same acronym &#8220;PHP,&#8221; and continues indefinitely.</p>
<h3>Why Should I Learn PHP?</h3>
<p>Any modern day web developer, or hobbyist even, should have at least a basic understand of what PHP is and how PHP works. More than <a href="http://royal.pingdom.com/2007/02/26/what-the-webs-most-popular-sites-are-running-on/" target="new">19 Million</a> websites are built on PHP code, many that we visit every day including: Facebook, Yahoo, Wikipedia, Flickr, Digg, any blog using wordpress, etc&#8230; And there are a lot of reasons why so many people choose to use PHP over other scripting languages.</p>
<p>Okay, so what can PHP do for me? Web pages written in HTML markup are static. The state of the page, and any info on the page cannot change without editing the file, and saving it again.</p>
<ul>
<li>PHP works seamlessly with HTML. Your PHP code can actually output HTML code&#8211;right along side your existing HTML. The two just work together.</li>
<li>PHP offers excellent integration with MySQL. If you are unsure of what this means, don&#8217;t worry. We&#8217;ll get to it over the next few articles.</li>
<li>PHP has a strong working user-base. What does this mean for you? It means that when you have problems and need answers. There are a lot of people that can help you.</li>
<li>PHP is open-source. Which means, it&#8217;s free!</li>
</ul>
<h3>What Do I Need to Get Started?</h3>
<p>All you need to get started with coding in PHP is a simple text editor and a server with PHP installed and running on it. Nearly every hosting company should offer PHP installed on their servers. However, if you&#8217;re working locally, which is what I&#8217;ll be doing, you will have to install PHP and an Apache server on your computer. This can be more difficult than one might think, so the solution that I recommend is to install a <a href="http://www.wampserver.com/en/download.php" target="new">WAMP</a> or <a href="http://www.mamp.info/en/downloads/index.html" target="new">MAMP</a> package, depending on what operating system you are working on. WAMP  and MAMP are both package local-hosting environment solutions. They combine, Windows (or Mac OS X) with Apache, MySQL, and PHP installations.</p>
<p>As far as text editors go, you could use Notepad (one Windows) or TextEdit (if you&#8217;re on a Mac)&#8211;I mean, those <em>will</em> work&#8230; However, you may want something with a few more helpful features such as syntax highlighting for better code readability, code folding, inline &#8220;auto-complete&#8221; typing aids, etc&#8230; If you&#8217;re using Windows, might I recommend using <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a> and if you&#8217;re using a Mac I suggest trying out <a href="http://www.barebones.com/products/TextWrangler/">Text Wrangler</a>. There are many other options-countless options, and many of them can get quite expensive, but the two I listed here are free to use.</p>
<p>Well, that about wraps up today&#8217;s first installment on how to get set up and running PHP on your machine, so you can start learning it. I would have liked this first article to go into language basics (at least). But I feel like I couldn&#8217;t start a learning series without an initial set-up guide. Next time we will begin going over the actual PHP language basics and understanding how it all works.</p>
]]></content:encoded>
			<wfw:commentRss>http://17webshop.com/2009/08/07/php-from-the-top-1-getting-set-up/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
