<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Cook .me &#187; chris cook</title>
	<atom:link href="http://chriscook.me/tag/chris-cook/feed/" rel="self" type="application/rss+xml" />
	<link>http://chriscook.me</link>
	<description>Homepage</description>
	<lastBuildDate>Sat, 31 Jul 2010 22:52:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Mac OS X Server Rejects Mail with No Subject Line</title>
		<link>http://chriscook.me/mac-2/mac-os-x-server-rejects-mail-with-no-subject-line/</link>
		<comments>http://chriscook.me/mac-2/mac-os-x-server-rejects-mail-with-no-subject-line/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 22:52:02 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[mac server]]></category>
		<category><![CDATA[mail rejected]]></category>
		<category><![CDATA[snow leopard server]]></category>

		<guid isPermaLink="false">http://chriscook.me/?p=122</guid>
		<description><![CDATA[Is Mac OS X Server 10.6 (Snow Leopard) rejecting your e-mail messages which lack a subject line? Mine was, and so does the default setting on Snow Leopard Server. Here&#8217;s a quick fix: 1) First, stop the mail service. 2 Now, you&#8217;ll want to edit the header_checks file that&#8217;s utilized by postfix. /^subject: *$/ REJECT [...]]]></description>
			<content:encoded><![CDATA[<p>Is Mac OS X Server 10.6 (Snow Leopard) rejecting your e-mail messages which lack a subject line?  Mine was, and so does the default setting on Snow Leopard Server.</p>
<p>Here&#8217;s a quick fix:</p>
<p><strong>1)</strong> First, stop the mail service.</p>
<p><strong>2</strong> Now, you&#8217;ll want to edit the header_checks file that&#8217;s utilized by postfix.  </p>
<pre class=""html">
sudo nano /etc/postfix/custom_header_checks
</pre>
<p>3) Next, you&#8217;ll see a line which says:</p>
<pre class=""html">
/^subject: *$/ REJECT empty subject header
</pre>
<p>Comment out this line by adding a pound sign (#) at the beginning of the line.</p>
<p>4) Once you comment out this line, it should appear as:</p>
<pre class=""html">
#/^subject: *$/ REJECT empty subject header
</pre>
<p>5) If you&#8217;re using nano or pico to edit the file, click Control+O to write the file.  (Save and Exit).</p>
<p>6) Now, restart the Mail service and the server will no longer reject email with no subject line.</p>
<p>&#8212;&#8212;-</p>
<p>Let me know if this solution works for you!  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/mac-2/mac-os-x-server-rejects-mail-with-no-subject-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Session Timeouts</title>
		<link>http://chriscook.me/web-development/php-session-timeouts/</link>
		<comments>http://chriscook.me/web-development/php-session-timeouts/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 22:31:50 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://chriscook.me/?p=117</guid>
		<description><![CDATA[Defining session timeout thresholds for PHP scripts is a security &#8220;must&#8221;. I recommend that you consider the purpose of your script before applying a session timeout function. For instance, if your site has a secure login and security requirements, it&#8217;s important to include the timeout function. However, it&#8217;s often an inconvenience to end-users. Use the [...]]]></description>
			<content:encoded><![CDATA[<p>Defining session timeout thresholds for PHP scripts is a security &#8220;must&#8221;.  I recommend that you consider the purpose of your script before applying a session timeout function.  For instance, if your site has a secure login and security requirements, it&#8217;s important to include the timeout function. However, it&#8217;s often an inconvenience to end-users.</p>
<p>Use the code below to create a function which can be used to implement a secure timeout threshold.</p>
<pre class="php">
<span class="phpComment">/* Set timeout threshold to 10 minutes <span class="phpOperator">(</span>600 seconds<span class="phpOperator">)</span> */</span>
@<span class="phpFunction">session_start</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
$timeout <span class="phpOperator">=</span> 600;
<span class="phpScriptVar">$_SESSION</span><span class="phpOperator">[</span><span class="phpString">"expires_by"</span><span class="phpOperator">]</span> <span class="phpOperator">=</span> <span class="phpFunction">time</span><span class="phpOperator">(</span><span class="phpOperator">)</span> <span class="phpOperator">+</span> $timeout;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/web-development/php-session-timeouts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clear Tower Consulting</title>
		<link>http://chriscook.me/projects/clear-tower-consulting/</link>
		<comments>http://chriscook.me/projects/clear-tower-consulting/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 06:37:09 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[clear tower consulting]]></category>
		<category><![CDATA[eLearning]]></category>
		<category><![CDATA[organizational development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://chriscook.me/?p=111</guid>
		<description><![CDATA[Looking for a company to help you manage your web development project? Need a website? Are you a looking for eLearning or online training? Clear Tower Consulting is a progressive, innovative firm which provides custom consulting solutions. Take a look at their services below (Excerpt from ClearTowerConsulting.com) eCommerce Solutions If you&#8217;re company sells products and [...]]]></description>
			<content:encoded><![CDATA[<p>Looking for a company to help you manage your web development project?  Need a website?  Are you a looking for eLearning or online training?</p>
<p>Clear Tower Consulting is a progressive, innovative firm which provides custom consulting solutions.</p>
<p>Take a look at their services below (Excerpt from <a href="http://www.cleartowerconsulting.com">ClearTowerConsulting.com</a>)</p>
<p><img src="http://www.cleartowerconsulting.com/images/CTC-Logo.png" alt="Clear Tower Consulting" /></p>
<p><strong>eCommerce Solutions</strong></p>
<p>If you&#8217;re company sells products and services, you need an eCommerce option on your web presence. Clear Tower Consulting has helped customers create shopping carts, customer management tools, and purchasing scripts since our establishment in 2003. We can integrate an existing 3rd party shopping cart with your website or we can develop a custom solution for your company. In addition, we&#8217;ll help you understand how merchant service providers operate and help you integrate your chosen provider with your web presence.</p>
<p>We&#8217;re profficient in many, many 3rd party eCommerce solutions including:<br />
- osCommerce<br />
- X-Cart<br />
- PHP Web Commerce<br />
- ClientExec<br />
- ModernBill (Parallels)</p>
<p><strong>Web Development and Management</strong></p>
<p>Websites are a critical element of every company&#8217;s business. We specialize in these services:<br />
- Website design (Web 2.0 technologies &#8211; CSS, XHTML)<br />
- Web Hosting<br />
- Web Application Development (PHP, MySQL, ASP, Access, MSSQL, Oracle)<br />
- Web Analytics<br />
- Web Surveys<br />
- Web Content Management</p>
<p><strong>Process Streamlining</strong></p>
<p>We&#8217;ve often heard the phrase, &#8220;a business is only as strong as its weakest link.&#8221; We agree, but we&#8217;re here to help. We specialize in facilitating group meetings, identifying process inefficincies, change management consulting, human resources strategies, project management streamlining, and much more. Ask one of our sales advisors about how we can help your business.</p>
<p><strong>eLearning Development</strong></p>
<p>We understand that today&#8217;s business environment requires companies (small and large) to re-think training and employee development. eLearning makes sense &#8212; it&#8217;s cost effective and allows the latest learning techniques.</p>
<p>Our custom eLearning courses feature:<br />
- Latest ISD technologies<br />
- Rich text<br />
- Rich media (videos, pictures, animations)<br />
- Quizzes, tests, and data capture<br />
- Interactive elements (drag and drop technology, memory clicks, etc.)<br />
- SCORM or AICC compliance<br />
- Integration with Learning Management Systems (LMS)</p>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/projects/clear-tower-consulting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use PHP to Backup your MySQL Database</title>
		<link>http://chriscook.me/web-development/backup-mysql-database-php/</link>
		<comments>http://chriscook.me/web-development/backup-mysql-database-php/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 20:00:13 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[automated backup]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[cron job]]></category>
		<category><![CDATA[databsae]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://chriscook.me/?p=104</guid>
		<description><![CDATA[If you don&#8217;t backup your databases regularly, shame on you. You should! The code below will allow you to generate a backup as often as you&#8217;d like. It only makes sense to run this via a CRON job. This is pretty easy to do and you can set the frequency as you wish. The backup [...]]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t backup your databases regularly, shame on you.  You should!</p>
<p>The code below will allow you to generate a backup as often as you&#8217;d like.  It only makes sense to run this via a CRON job.  This is pretty easy to do and you can set the frequency as you wish.</p>
<p>The backup files will be stored in the same directory as this script.  </p>
<p><em><strong>Please leave feedback and let me know if this works for you!</strong></em></p>
<p>Here&#8217;s the PHP code:</p>
<pre class="php">
backup_tables<span class="phpOperator">(</span><span class="phpString">'localhost'</span>,<span class="phpString">'username'</span>,<span class="phpString">'password'</span>,<span class="phpString">'blog'</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">// Backup the entire database or just a specific table.
</span><span class="phpFunctionKeyword">function</span> backup_tables<span class="phpOperator">(</span>$host,$user,$pass,$name,$tables <span class="phpOperator">=</span> <span class="phpString">'*'</span><span class="phpOperator">)</span>
<span class="phpOperator">{</span>
	$link <span class="phpOperator">=</span> <span class="phpFunction">mysql_connect</span><span class="phpOperator">(</span>$host,$user,$pass<span class="phpOperator">)</span><span class="phpText">;</span>
	<span class="phpFunction">mysql_select_db</span><span class="phpOperator">(</span>$name,$link<span class="phpOperator">)</span><span class="phpText">;</span>
	<span class="phpComment">//get all of the tables
</span><span class="phpKeyword">	if<span class="phpOperator">(</span></span>$tables <span class="phpOperator"><span class="phpOperator">=</span>=</span> <span class="phpString">'*'</span><span class="phpOperator">)</span>
	<span class="phpOperator">{</span>
		$tables <span class="phpOperator">=</span> <span class="phpFunction">array</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
		$result <span class="phpOperator">=</span> <span class="phpFunction">mysql_query</span><span class="phpOperator">(</span><span class="phpString">'SHOW TABLES'</span><span class="phpOperator">)</span><span class="phpText">;</span>
	<span class="phpKeyword">	while<span class="phpOperator">(</span></span>$row <span class="phpOperator">=</span> <span class="phpFunction">mysql_fetch_row</span><span class="phpOperator">(</span>$result<span class="phpOperator">)</span><span class="phpOperator">)</span>
		<span class="phpOperator">{</span>
			$tables<span class="phpOperator">[</span><span class="phpOperator">]</span> <span class="phpOperator">=</span> $row<span class="phpOperator">[</span><span class="phpNumber">0</span><span class="phpOperator">]</span><span class="phpText">;</span>
		<span class="phpOperator">}</span>
	<span class="phpOperator">}</span>
<span class="phpKeyword">	else
</span>
	<span class="phpOperator">{</span>
		$tables <span class="phpOperator">=</span> is_<span class="phpFunction">array</span><span class="phpOperator">(</span>$tables<span class="phpOperator">)</span> <span class="phpOperator">?</span> $tables <span class="phpOperator">:</span> <span class="phpFunction">explode</span><span class="phpOperator">(</span><span class="phpString">','</span>,$tables<span class="phpOperator">)</span><span class="phpText">;</span>
	<span class="phpOperator">}</span>
	<span class="phpComment">//This method is completed<span class="phpKeyword"> for </span>each table
</span><span class="phpKeyword">	foreach<span class="phpOperator">(</span></span>$tables<span class="phpKeyword"> as </span>$table<span class="phpOperator">)</span>
	<span class="phpOperator">{</span>
		$result <span class="phpOperator">=</span> <span class="phpFunction">mysql_query</span><span class="phpOperator">(</span><span class="phpString">'SELECT * FROM '</span>.$table<span class="phpOperator">)</span><span class="phpText">;</span>
		$num_fields <span class="phpOperator">=</span> <span class="phpFunction">mysql_num_fields</span><span class="phpOperator">(</span>$result<span class="phpOperator">)</span><span class="phpText">;</span>
		$return<span class="phpOperator">.=</span> <span class="phpString">'DROP TABLE '</span>.$table.<span class="phpString">'<span class="phpText">;</span>'</span><span class="phpText">;</span>
		$row2 <span class="phpOperator">=</span> <span class="phpFunction">mysql_fetch_row</span><span class="phpOperator">(</span><span class="phpFunction">mysql_query</span><span class="phpOperator">(</span><span class="phpString">'SHOW CREATE TABLE '</span>.$table<span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
		$return<span class="phpOperator">.=</span> <span class="phpString">"\n\n"</span>.$row2<span class="phpOperator">[</span><span class="phpNumber">1</span><span class="phpOperator">]</span>.<span class="phpString">"<span class="phpText">;</span>\n\n"</span><span class="phpText">;</span>
	<span class="phpKeyword">	for </span><span class="phpOperator">(</span>$i <span class="phpOperator">=</span> 0; $i <span class="phpOperator">&lt;</span> $num_fields<span class="phpText">;</span> $i<span class="phpOperator"><span class="phpOperator">+</span><span class="phpOperator">+</span></span><span class="phpOperator">)</span>
		<span class="phpOperator">{</span>
		<span class="phpKeyword">	while<span class="phpOperator">(</span></span>$row <span class="phpOperator">=</span> <span class="phpFunction">mysql_fetch_row</span><span class="phpOperator">(</span>$result<span class="phpOperator">)</span><span class="phpOperator">)</span>
			<span class="phpOperator">{</span>
				$return<span class="phpOperator">.=</span> <span class="phpString">'INSERT INTO '</span>.$table.<span class="phpString">' VALUES<span class="phpOperator">(</span>'</span><span class="phpText">;</span>
			<span class="phpKeyword">	for<span class="phpOperator">(</span></span>$j<span class="phpOperator">=</span>0; $j<span class="phpOperator">&lt;</span>$num_fields<span class="phpText">;</span> $j<span class="phpOperator"><span class="phpOperator">+</span><span class="phpOperator">+</span></span><span class="phpOperator">)</span>
				<span class="phpOperator">{</span>
					$row<span class="phpOperator">[</span>$j<span class="phpOperator">]</span> <span class="phpOperator">=</span> <span class="phpFunction">addslashes</span><span class="phpOperator">(</span>$row<span class="phpOperator">[</span>$j<span class="phpOperator">]</span><span class="phpOperator">)</span><span class="phpText">;</span>
					$row<span class="phpOperator">[</span>$j<span class="phpOperator">]</span> <span class="phpOperator">=</span> <span class="phpFunction">ereg_replace</span><span class="phpOperator">(</span><span class="phpString">"\n"</span>,<span class="phpString">"\\n"</span>,$row<span class="phpOperator">[</span>$j<span class="phpOperator">]</span><span class="phpOperator">)</span><span class="phpText">;</span>
				<span class="phpKeyword">	if </span><span class="phpOperator">(</span><span class="phpFunction">isset</span><span class="phpOperator">(</span>$row<span class="phpOperator">[</span>$j<span class="phpOperator">]</span><span class="phpOperator">)</span><span class="phpOperator">)</span> <span class="phpOperator">{</span> $return<span class="phpOperator">.=</span> <span class="phpString">'<span class="phpString">"'</span>.$row<span class="phpOperator">[</span>$j<span class="phpOperator">]</span>.<span class="phpString">'"' ; } else { $return.= '""</span>'</span><span class="phpText">;</span> <span class="phpOperator">}</span>
				<span class="phpKeyword">	if </span><span class="phpOperator">(</span>$j<span class="phpOperator">&lt;</span><span class="phpOperator">(</span>$num_fields-<span class="phpNumber">1</span><span class="phpOperator">)</span><span class="phpOperator">)</span> <span class="phpOperator">{</span> $return<span class="phpOperator">.=</span> <span class="phpString">','</span><span class="phpText">;</span> <span class="phpOperator">}</span>
				<span class="phpOperator">}</span>
				$return<span class="phpOperator">.=</span> <span class="phpString">"<span class="phpOperator">)</span><span class="phpText">;</span>\n"</span><span class="phpText">;</span>
			<span class="phpOperator">}</span>
		<span class="phpOperator">}</span>
		$return<span class="phpOperator">.=</span><span class="phpString">"\n\n\n"</span><span class="phpText">;</span>
	<span class="phpOperator">}</span>
	<span class="phpComment">//Now, we<span class="phpString">'ll save the <span class="phpFunction">file</span>
</span>	$handle <span class="phpOperator">=</span> <span class="phpFunction">fopen</span><span class="phpOperator">(</span>'</span>backup-<span class="phpString">'<span class="phpOperator">.</span><span class="phpFunction">time</span><span class="phpOperator">(</span><span class="phpOperator">)</span>.'</span>-<span class="phpString">'<span class="phpOperator">.</span><span class="phpOperator">(</span><span class="phpFunction">md5</span><span class="phpOperator">(</span><span class="phpFunction">implode</span><span class="phpOperator">(</span>'</span>,<span class="phpString">',$tables<span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpOperator">)</span>.'</span>.sql<span class="phpString">','</span>w<span class="phpOperator">+</span>&#039;<span class="phpOperator">)</span><span class="phpText">;</span>
	<span class="phpFunction">fwrite</span><span class="phpOperator">(</span>$handle,$return<span class="phpOperator">)</span><span class="phpText">;</span>
	<span class="phpFunction">fclose</span><span class="phpOperator">(</span>$handle<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">}</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/web-development/backup-mysql-database-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Return Random Record via MySQL</title>
		<link>http://chriscook.me/web-development/return-random-record-via-mysql/</link>
		<comments>http://chriscook.me/web-development/return-random-record-via-mysql/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 20:01:54 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[RAND]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://chriscook.me/?p=96</guid>
		<description><![CDATA[There are many practical and frequently used methods requiring a random record to be called. For instance, when you see &#8220;featured profiles&#8221; or random customer comments on a website, they are most likely using a function to call a random record. In addition, this function can allow you to display data in a random order. [...]]]></description>
			<content:encoded><![CDATA[<p>There are many practical and frequently used methods requiring a random record to be called.  For instance, when you see &#8220;featured profiles&#8221; or random customer comments on a website, they are most likely using a function to call a random record.</p>
<p>In addition, this function can allow you to display data in a random order.</p>
<p>Here&#8217;s how it works:</p>
<pre class="mysql">
SELECT field_1, field_2, field_3, field_4
FROM table_name
WHERE parameter = 1
ORDER BY RAND()
LIMIT 1
</pre>
<p>It&#8217;s that simple.  Please post your feedback!</p>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/web-development/return-random-record-via-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: Preventing typical XSS attacks</title>
		<link>http://chriscook.me/web-development/php-preventing-typical-xss-attacks/</link>
		<comments>http://chriscook.me/web-development/php-preventing-typical-xss-attacks/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 17:36:44 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[cross-site scripting]]></category>
		<category><![CDATA[htmlentities]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[prevent xss]]></category>
		<category><![CDATA[transform_HTML]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xss]]></category>
		<category><![CDATA[xss attacks]]></category>

		<guid isPermaLink="false">http://chriscook.me/?p=71</guid>
		<description><![CDATA[XSS attacks plague beginner programmers and are a significant vulnerability for commercial web hosts &#38; website operators.  XSS means &#8220;cross-site scripting&#8220;.  These exploits work on the client side. Often, hackers put some type of JavaScript in content that users submit that allow them to steal the data from a cookie.  XSS attacks are pretty difficult [...]]]></description>
			<content:encoded><![CDATA[<p>XSS attacks plague beginner programmers and are a significant vulnerability for commercial web hosts &amp; website operators.  XSS means &#8220;<strong>cross-site scripting</strong>&#8220;.  These exploits work on the client side. Often, hackers put some type of JavaScript in content that users submit that allow them to steal the data from a cookie.  XSS attacks are pretty difficult to prevent.  Hackers have been successful with XSS attacks on most, if not all, of the biggest sites on the net.</p>
<p>To help prevent XSS attacks, it&#8217;s best to restrict and filter the data that you get from a user through your site.  Have you ever wondered why popular bulletin boards, such as vB or phpBB, use custom tag formats like [url] or [b]?  They&#8217;re trying to prevent attacks.</p>
<p>This tutorial is a very basic example of a way to help prevent XSS attacks.  There are other methods &#8212; and more comprehensive methods out there.</p>
<p><strong>okHTML function:</strong><br />
Let&#8217;s start with a simple function that converts any HTML code (or character) into literals.</p>
<pre class="php">
<span class="phpComment">// ChrisCook<span class="phpOperator">.</span>me
</span><span class="phpFunctionKeyword">function</span> ok_HTML<span class="phpOperator">(</span>$string, $length <span class="phpOperator">=</span> null<span class="phpOperator">)</span>
<span class="phpOperator">{</span>
<span class="phpComment">// get rid of the extra space
</span>$string <span class="phpOperator">=</span> <span class="phpFunction">trim</span><span class="phpOperator">(</span>$string<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">// avoid unicode codec issues
</span>$string <span class="phpOperator">=</span> <span class="phpFunction">utf8_decode</span><span class="phpOperator">(</span>$string<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">// convert HTML characters
</span>$string <span class="phpOperator">=</span> <span class="phpFunction">htmlentities</span><span class="phpOperator">(</span>$string, <span class="phpConstant">ENT_NOQUOTES</span><span class="phpOperator">)</span><span class="phpText">;</span>
$string <span class="phpOperator">=</span> <span class="phpFunction">str_replace</span><span class="phpOperator">(</span><span class="phpString">"#"</span>, <span class="phpString">"#"</span>, $string<span class="phpOperator">)</span><span class="phpText">;</span>
$string <span class="phpOperator">=</span> <span class="phpFunction">str_replace</span><span class="phpOperator">(</span><span class="phpString">"%"</span>, <span class="phpString">"%"</span>, $string<span class="phpOperator">)</span><span class="phpText">;</span>
$length <span class="phpOperator">=</span> <span class="phpFunction">intval</span><span class="phpOperator">(</span>$length<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
if<span class="phpOperator">(</span></span>$length <span class="phpOperator">&gt;</span> <span class="phpNumber">0</span><span class="phpOperator">)</span> <span class="phpOperator">{</span>
$string <span class="phpOperator">=</span> <span class="phpFunction">substr</span><span class="phpOperator">(</span>$string, <span class="phpNumber">0</span>, $length<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">}</span>
<span class="phpKeyword">
return </span>$string;
<span class="phpOperator">}</span>
</pre>
<p><strong>The Explanation:</strong><br />
One  of the  most important components of that function is the htmlentities() funcion call that converts <strong>&amp;</strong>, <strong>&lt;</strong>, and <strong>&gt;</strong> into <strong>&amp;amp;</strong>, <strong>&amp;lt;</strong>, and <strong>&amp;gt;</strong>. This helps resolve the simple hacks.  We&#8217;re not done yet, though.  All XSS attacks aren&#8217;t basic.  Hackers know programmers have implemented these attacks to they tend to encode their hacks and malicious scripts in UTF-8 or hexadecimal instead of using the normal ASCII text.</p>
<p>To help prevent this, transform_HTML() takes the additional step of converting # and % signs into the correct entities.</p>
<p>In my readings on preventing XSS attacks, many experts recommend that you limit the  string length in case some goober tries to overload your string with a very, very long input in hopes that they&#8217;ll crash the server or your database. You can edit the <strong>$length</strong> parameter to help control this.</p>
<p>That&#8217;s it for today,<br />
<em>Chris</em></p>
<p><strong>Disclaimer: </strong>As always, I want to add my handy-dandy disclaimer.  Please understand that this tutorial is intended to demonstrate a specific function.  Please review the code and add appropriate security measures before using it in a production environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/web-development/php-preventing-typical-xss-attacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP/AJAX: Call PHP function by clicking a link</title>
		<link>http://chriscook.me/web-development/phpajax-execute-php-function-by-clicking-a-link/</link>
		<comments>http://chriscook.me/web-development/phpajax-execute-php-function-by-clicking-a-link/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 22:14:24 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[chriscook.me]]></category>
		<category><![CDATA[execute php function in ajax request]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://chriscook.me/?p=46</guid>
		<description><![CDATA[This tutorial demonstrates how to execute an external PHP function by clicking a simple link within HTML.  The method uses AJAX so that the page doesn&#8217;t refresh and doesn&#8217;t require a form submission. 1) Paste the following code into a .js file.  For demonstration purposes, we have named it &#8220;ajax_click.js&#8221;. /* * ajax_click.js * chriscook.me [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial demonstrates how to execute an external PHP function by clicking a simple link within HTML.  The method uses AJAX so that the page doesn&#8217;t refresh and doesn&#8217;t require a form submission.</p>
<p><strong>1)</strong> Paste the following code into a .js file.  For demonstration purposes, we have named it &#8220;ajax_click.js&#8221;.</p>
<pre class="html">
/*
* ajax_click.js
*  chriscook.me
*/
function loadurl(dest) {
try {
// Moz supports XMLHttpRequest. IE uses ActiveX.
// browser detction is bad. object detection works for any browser
xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
} catch (e) {
// browser doesn&#039;t support ajax. handle however you want
}
// the xmlhttp object triggers an event everytime the status changes
// triggered() function handles the events
xmlhttp.onreadystatechange = triggered;
// open takes in the HTTP method and url.
xmlhttp.open(&quot;GET&quot;, dest);
// send the request. if this is a POST request we would have
// sent post variables: send(&quot;name=aleem gender=male)
// Moz is fine with just send(); but
// IE expects a value here, hence we do send(null);
xmlhttp.send(&quot;null&quot;);
}
function triggered() {
if ((xmlhttp.readyState == 4) (xmlhttp.status == 200)) {
document.getElementById(&quot;ajaxlink&quot;).innerHTML = xmlhttp.responseText;
}
}
</pre>
<p><strong>2)</strong> Next, add the following code in the  section of your HTML file.</p>
<pre class="html"><span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;ajax_link.js&quot;</span> type=<span class="htmlAttributeValue">&quot;text/javascript&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span></pre>
<p><strong>3)</strong> The following code should be placed in the HTML body of a PHP file.</p>
<pre class="html">
<span class="htmlOtherTag">&lt;div id=<span class="htmlAttributeValue">&quot;ajaxlink&quot;</span> onclick=<span class="htmlAttributeValue">&quot;loadurl(&#039;ajax_function.php&#039;)&quot;</span>&gt;</span>Click Here<span class="htmlOtherTag">&lt;/div&gt;</span>
</pre>
<p>Replace &#8216;ajax_function.php&#8217; with the correct file you want to execute.  For instance, if you want your users to &#8220;click here&#8221; in order to send themselves a copy of their monthly invoice, you&#8217;d code the mailer function in &#8216;ajax_function.php&#8217;.</p>
<p><strong>4) </strong>That&#8217;s it.  Ensure that you keep the &lt;div&gt; id  as &#8220;ajaxlink&#8221;.  Once you click the link, it will disappear (until the page is refreshed).</p>
<p><strong>Feedback:</strong> I&#8217;d love to hear how you&#8217;ve used this tool.  Please feel free to post a comment on my blog.</p>
<p><strong>Disclaimer: </strong> This tutorial is provided to demonstrate how to perform the function.  Please ensure that you review the code and add security measures before using this in a production environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/web-development/phpajax-execute-php-function-by-clicking-a-link/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>&#8220;Lock Desktop&#8221; &#8211; New Mac OS X App</title>
		<link>http://chriscook.me/featured-articles/new-mac-os-x-application-lock-desktop/</link>
		<comments>http://chriscook.me/featured-articles/new-mac-os-x-application-lock-desktop/#comments</comments>
		<pubDate>Sun, 15 Apr 2007 23:25:59 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[automator]]></category>
		<category><![CDATA[chris cook]]></category>
		<category><![CDATA[lock desktop]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mac os x]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[WINDOWS+L]]></category>

		<guid isPermaLink="false">http://chriscook.info/?p=8</guid>
		<description><![CDATA[I&#8217;ve uploaded one of my first applications for a Mac. It&#8217;s extremely easy to use. The tool allows you to lock your desktop when you&#8217;re away from the computer and requires a password when you get back.  This is something you can run on demand, instead of waiting for a screen-saver, or logging off.  Lock [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve uploaded one of my first applications for a Mac.  It&#8217;s extremely easy to use.  The tool allows you to lock your desktop when you&#8217;re away from the computer and requires a password when you get back.  This is something you can run on demand, instead of waiting for a screen-saver, or logging off.  Lock Desktop 1.0 even keeps your programs running in the back. <span id="more-19"></span></p>
<p><span style="font-weight: bold"><span style="font-style: italic">Download the file below.<br />
<span style="font-style: normal; font-weight: normal"><a title="Lock Desktop - Mac OS X" href="http://chriscook.me/wp-content/uploads/2008/09/lock_desktop.zip"></a></span></span></span><span style="font-weight: bold"><span style="font-style: italic"><span style="font-style: normal; font-weight: normal"><a title="Lock Desktop - Mac OS X" href="http://chriscook.me/wp-content/plugins/download-monitor/download.php?id=1"><span style="font-weight: bold">Lock Desktop &#8211; Mac OS X</span></a> </span></span></span></p>
<p>Mac OS X &#8211; Application that will &#8220;lock&#8221; desktop.  This feature was available on my PC and allowed to leave my workstation and ensure that my desktop remained safe.  This application runs an Automator script to lock the desktop.</p>
<p><script type='text/javascript' src='http://www.macupdate.com/developer/badge/?app=25190'></script></p>
]]></content:encoded>
			<wfw:commentRss>http://chriscook.me/featured-articles/new-mac-os-x-application-lock-desktop/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
	</channel>
</rss>
