<?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>VV&#039;s Corner &#187; howto</title>
	<atom:link href="http://vinoaj.com/blog/category/howtos/feed/" rel="self" type="application/rss+xml" />
	<link>http://vinoaj.com/blog</link>
	<description>my collection of random thoughts, how-to&#039;s and code snippets</description>
	<lastBuildDate>Sat, 04 Dec 2010 15:05:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Triggering the Source Code view of the current page using JavaScript</title>
		<link>http://vinoaj.com/blog/2008/03/triggering-the-source-code-view-of-the-current-page-using-javascript/</link>
		<comments>http://vinoaj.com/blog/2008/03/triggering-the-source-code-view-of-the-current-page-using-javascript/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 22:40:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/uncategorized/triggering-the-source-code-view-of-the-current-page-using-javascript/</guid>
		<description><![CDATA[I was recently writing a demo to showcase the new Google Language API, and in my demo I did the usual thing of instructing users to View &#62; Page Source in order to view the source code and comments. I know this is less than ideal, because it forces users to have to process the [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently writing a <a href="http://vinoaj.com/google/language" title="Google Language API demo" target="_blank">demo to showcase the new Google Language API</a>, and in my demo I did the usual thing of instructing users to View &gt; Page Source in order to view the source code and comments.  I know this is less than ideal, because it forces users to have to process the instructions, and then execute them.  Somewhere in there you lose them and they never execute the desired action.</p>
<p>It got me thinking: is there a way to have the source code in front of them in one click?  A few Google searches later, and the answer was yes!</p>
<p>Using JavaScript you can open a new window to display the source code view of the current window:</p>
<div class="igBar"><span id="ljavascript-2"><a href="#" onclick="javascript:showPlainTxt('javascript-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-2">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">window.<span style="color: #000066;">open</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'view-source:'</span> + window.<span style="color: #006600;">location</span>.<span style="color: #006600;">href</span>, <span style="color: #3366CC;">'mysource'</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Voila!  How easy was that?  Now it's your turn.</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2008/03/triggering-the-source-code-view-of-the-current-page-using-javascript/&via=vinoaj&text=Triggering the Source Code view of the current page using JavaScript&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2008/03/triggering-the-source-code-view-of-the-current-page-using-javascript/&via=vinoaj&text=Triggering the Source Code view of the current page using JavaScript&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2008%2F03%2Ftriggering-the-source-code-view-of-the-current-page-using-javascript%2F&amp;title=Triggering%20the%20Source%20Code%20view%20of%20the%20current%20page%20using%20JavaScript" id="wpa2a_2"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2008/03/triggering-the-source-code-view-of-the-current-page-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recommended Mozilla Firefox add-ons (aka extensions, aka plugins)</title>
		<link>http://vinoaj.com/blog/2007/07/recommended-mozilla-firefox-add-ons-aka-extensions-aka-plugins/</link>
		<comments>http://vinoaj.com/blog/2007/07/recommended-mozilla-firefox-add-ons-aka-extensions-aka-plugins/#comments</comments>
		<pubDate>Mon, 30 Jul 2007 02:15:19 +0000</pubDate>
		<dc:creator>vinoaj</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/javascript/recommended-mozilla-firefox-add-ons-aka-extensions-aka-plugins/</guid>
		<description><![CDATA[This is a list of my "must-have" Mozilla Firefox add-ons. If you can recommend anything similar or better, be sure to drop me a comment. Page Analysis &#38; SEO Minimise Nuisance Bookmark Management Download Management Productivity Web Development &#38; Design Security Functional Extensions Tab Management Add-Ons Management Page Analysis &#38; SEO About This Site Bookmarks [...]]]></description>
			<content:encoded><![CDATA[<p>This is a list of my "must-have" <a href="https://addons.mozilla.org/en-US/firefox/" target="_blank">Mozilla Firefox add-ons</a>.  If you can recommend anything similar or better, be sure to drop me a comment.</p>
<hr />
<a href="#pageanalyis">Page Analysis &amp; SEO</a><br />
<a href="#nuisance">Minimise Nuisance</a><br />
<a href="#bookmarks">Bookmark Management</a><br />
<a href="#downloads">Download Management</a><br />
<a href="#productivity">Productivity</a><br />
<a href="#webdev">Web Development &amp; Design</a><br />
<a href="#security">Security</a><br />
<a href="#functional">Functional Extensions</a><br />
<a href="#tabs">Tab Management</a><br />
<a href="#addons">Add-Ons Management</a></p>
<hr /><a title="pageanalysis" name="pageanalysis"></a></p>
<h2>Page Analysis &amp; SEO</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/3673" target="_blank"><strong>About This Site Bookmarks</strong></a> - right-click on a page, select "About This Site Bookmarks" and you will see a list of handy links pointing off to informational sites such as Alexa, Compete, Netcraft, del.icio.us, etc.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/321" target="_blank"><strong>SearchStatus</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/590" target="_blank"><strong>ShowIP</strong></a></p>
<hr />
<a title="nuisance" name="nuisance"></a></p>
<h2>Minimising Nuisance</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/1865" target="_blank"><strong>Adblock Plus</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/1136" target="_blank"><strong>Adblock Filterset.G Updater</strong></a></p>
<hr />
<a title="bookmarks" name="bookmarks"></a></p>
<h2>Bookmark Management</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/11" target="_blank"><strong>Add Bookmark Here</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/1553" target="_blank"><strong>Bookmark Duplicate Detector</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/3615" target="_blank"><strong>del.icio.us</strong></a></p>
<hr />
<a title="downloads" name="downloads"></a></p>
<h2>Download Management</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/26" target="_blank"><strong>Download Statusbar</strong></a> - manage your downloads via the Firefox status bar.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/201" target="_blank"><strong>DownThemAll</strong></a> - conveniently download all link targets on a page.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/220" target="_blank"><strong>FlashGot</strong></a> - allows for single and multiple downloads utilising an external download manager of your choice (I prefer FlashGet).</p>
<hr />
<a title="productivity" name="productivity"></a></p>
<h2>Productivity</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/383" target="_blank"><strong>Auto Copy</strong></a> - highlight a piece of text and the selection is automatically copied to your clipboard.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/1117" target="_blank"><strong>FoxClocks</strong></a> - displays local times around the world in the statusbar or toolbar.  Great for if you are dealing with friends and colleagues across multiple timezones.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/219" target="_blank"><strong>FoxyTunes</strong></a> - operate your currently running media player from your Firefox statusbar.</p>
<p><a href="http://www.google.com/notebook" target="_blank"><strong>Google Notebook</strong></a> - conveniently clip text and links to your Google Notebook.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/190" target="_blank"><strong>Linkification</strong></a> - Converts text links (including e-mail addresses) into clickable links.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/636" target="_blank"><strong>PDF Download</strong></a></p>
<hr />
<a title="webdev" name="webdev"></a></p>
<h2>Web Development &amp; Design</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/271" target="_blank"><strong>ColorZilla</strong></a> - eye-dropper tool that allows you to pick the HEX &amp; RGB values of colours of elements on the page.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/1843" target="_blank"><strong>Firebug</strong></a> - the quintessential Javascript debugger.  It also allows for excellent DOM and CSS debugging and manipulation.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/images/addon_icon/249" target="_blank"><strong>HTML Validator</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/35" target="_blank"><strong>IE View</strong></a> - open the current page in an IE window.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/3829" target="_blank"><strong>Live HTTP Headers</strong></a> - view HTTP request and response headers in realtime.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/59" target="_blank"><strong>User Agent Switcher</strong></a> - allows you to spoof the User-Agent string and have Firefox masquerade as the Googlebot, etc, to see how your site reacts to different user-agents.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/655" target="_blank"><strong>View Source Chart</strong></a> - renders page source HTML in an easy-to-read manner.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/60" target="_blank"><strong>Web Developer</strong></a> - a must for the serious web developer.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/5369" target="_blank"><strong>YSlow</strong></a> - an addon to the Firebug debugger.  It allows you to profile a page and identify bottlenecks.  Provided by Yahoo.  Also see Yahoo's articles on improving page load performance.</p>
<hr />
<a title="security" name="security"></a></p>
<h2>Security</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/2497" target="_blank"><strong>CookieSafe</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/4510" target="_blank"><strong>Edit Cookies</strong></a></p>
<p><a href="http://www.siteadvisor.com/download/ff.html" target="_blank"><strong>McAfee SiteAdvisor</strong></a> - lets you know if the currently viewed site is considered "safe" or not.</p>
<p><a title="functional" name="functional"></a></p>
<h2>Functionality Extensions</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/743" target="_blank"><strong>CustomizeGoogle</strong></a> - customize your Google search and application experiences.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/3336" target="_blank"><strong>ErrorZilla</strong></a> - extends the standard page not found error screen with convenient links such as access to the page's Google cached copy.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/4429" target="_blank"><strong>Secure Login</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/315" target="_blank"><strong>View Cookies</strong></a></p>
<hr />
<a title="tabs" name="tabs"></a></p>
<h2>Tab Management</h2>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/3780" target="_blank"><strong>Faviconize Tab</strong></a> - minimize a tab's width to the width of the favicon.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/1122" target="_blank"><strong>Tab Mix Plus</strong></a></p>
<hr />
<a title="addons" name="addons"></a></p>
<h2>Add-Ons Management</h2>
<p><a href="http://www.google.com/tools/firefox/browsersync/" target="_blank"><strong>Google Browser Sync</strong></a></p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/2109" target="_blank"><strong>FEBE</strong></a> - a convenient extensions &amp; settings backup tool.  Allows you to also run scheduled backups.  The backups can be used to transport your extensions and their settings to another machine or Firefox profile.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/421" target="_blank"><strong>MR Tech Local Install</strong></a> - install power tools for add-ons</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/recommended-mozilla-firefox-add-ons-aka-extensions-aka-plugins/&via=vinoaj&text=Recommended Mozilla Firefox add-ons (aka extensions, aka plugins)&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/recommended-mozilla-firefox-add-ons-aka-extensions-aka-plugins/&via=vinoaj&text=Recommended Mozilla Firefox add-ons (aka extensions, aka plugins)&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F07%2Frecommended-mozilla-firefox-add-ons-aka-extensions-aka-plugins%2F&amp;title=Recommended%20Mozilla%20Firefox%20add-ons%20%28aka%20extensions%2C%20aka%20plugins%29" id="wpa2a_4"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/07/recommended-mozilla-firefox-add-ons-aka-extensions-aka-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>scp Usage</title>
		<link>http://vinoaj.com/blog/2007/07/scp-usage/</link>
		<comments>http://vinoaj.com/blog/2007/07/scp-usage/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 11:34:03 +0000</pubDate>
		<dc:creator>vinoaj</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/scp-usage/</guid>
		<description><![CDATA[Secure File Copy (scp) allows you to copy files between hosts using the SSH protocol. To copy from a remote host to your current host PLAIN TEXT PERL: scp -r user@remotehost:path/to/remotefiles localtarget &#160; #-r recursive copy #you will be prompted for user's password @ remotehost To copy files from your current host across to the [...]]]></description>
			<content:encoded><![CDATA[<p>Secure File Copy (scp) allows you to copy files between hosts using the SSH protocol.</p>
<p>To copy from a remote host to your current host</p>
<div class="igBar"><span id="lperl-5"><a href="#" onclick="javascript:showPlainTxt('perl-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PERL:</span>
<div id="perl-5">
<div class="perl">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">scp -r user<span style="color: #0000ff;">@remotehost</span>:path/to/remotefiles localtarget</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#-r recursive copy</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#you will be prompted for user's password @ remotehost </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>To copy files from your current host across to the remote host</p>
<div class="igBar"><span id="lperl-6"><a href="#" onclick="javascript:showPlainTxt('perl-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PERL:</span>
<div id="perl-6">
<div class="perl">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">scp -r localfiles user<span style="color: #0000ff;">@remotehost</span>:path/to/remotetarget </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/scp-usage/&via=vinoaj&text=scp Usage&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/scp-usage/&via=vinoaj&text=scp Usage&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F07%2Fscp-usage%2F&amp;title=scp%20Usage" id="wpa2a_6"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/07/scp-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selecting a random row using MySQL</title>
		<link>http://vinoaj.com/blog/2007/07/selecting-a-random-row-using-mysql/</link>
		<comments>http://vinoaj.com/blog/2007/07/selecting-a-random-row-using-mysql/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 08:54:58 +0000</pubDate>
		<dc:creator>vinoaj</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/selecting-a-random-row-using-mysql/</guid>
		<description><![CDATA[There are many examples where you would need to retrieve a random record or more from a set of tables. For example your page template may be cycling through QOTDs, testimonials, offers, specials, and so forth. To retrieve a random row in MySQL, use the ORDER BY RAND() statement to randomly order the rows of [...]]]></description>
			<content:encoded><![CDATA[<p>There are many examples where you would need to retrieve a random record or more from a set of tables.  For example your page template may be cycling through QOTDs, testimonials, offers, specials, and so forth.</p>
<p>To retrieve a random row in MySQL, use the <code>ORDER BY RAND()</code> statement to randomly order the rows of a table.  Then use <code>LIMIT x</code> to retrieve the first <code>x</code> rows from the randomised representation of the table.</p>
<p>For example:</p>
<div class="igBar"><span id="lsql-9"><a href="#" onclick="javascript:showPlainTxt('sql-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-9">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/*&nbsp; Retrieve 5 random special offers to display in your e-commerce store's sidebar */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span>&nbsp; offer_id</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">FROM</span>&nbsp; &nbsp; special_offers</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> RAND<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;color:#800000;">5</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Of course, we can make our query as complex as needed, and then randomly order the resultset.</p>
<div class="igBar"><span id="lsql-10"><a href="#" onclick="javascript:showPlainTxt('sql-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-10">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span>&nbsp; so.offer_id, i.title</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">FROM</span>&nbsp; &nbsp; special_offers so</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> items i <span style="color: #993333; font-weight: bold;">ON</span> <span style="color:#006600; font-weight:bold;">&#40;</span>so.item_id = i.item_id<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> item_categories ic <span style="color: #993333; font-weight: bold;">ON</span> <span style="color:#006600; font-weight:bold;">&#40;</span>i.item_id = ic.item_id<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">WHERE</span>&nbsp; &nbsp;ic.category_id = <span style="color: #cc66cc;color:#800000;">2344</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> RAND<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;color:#800000;">5</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/selecting-a-random-row-using-mysql/&via=vinoaj&text=Selecting a random row using MySQL&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/selecting-a-random-row-using-mysql/&via=vinoaj&text=Selecting a random row using MySQL&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F07%2Fselecting-a-random-row-using-mysql%2F&amp;title=Selecting%20a%20random%20row%20using%20MySQL" id="wpa2a_8"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/07/selecting-a-random-row-using-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP code snippet &#8211; Reorder items in a table</title>
		<link>http://vinoaj.com/blog/2007/07/php-code-snippet-reorder-items-in-a-table/</link>
		<comments>http://vinoaj.com/blog/2007/07/php-code-snippet-reorder-items-in-a-table/#comments</comments>
		<pubDate>Mon, 09 Jul 2007 10:00:15 +0000</pubDate>
		<dc:creator>vinoaj</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/php-code-snippet-reorder-items-in-a-table/</guid>
		<description><![CDATA[This snippet of code reorders items in a table based on the number of steps you want to move an item from its current position. It moves the item of interest to its new position and shifts all other items to their new shifted positions. PLAIN TEXT PHP: function moveItem &#40;$n_steps&#41; &#123; if &#40;$n_steps == [...]]]></description>
			<content:encoded><![CDATA[<p>This snippet of code reorders items in a table based on the number of steps you want to move an item from its current position.  It moves the item of interest to its new position and shifts all other items to their new shifted positions.</p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-12">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> moveItem <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$n_steps</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$n_steps</span> == <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">return</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$cur_pos</span> = <span style="color:#0000FF;">$this</span>-&amp;gt;pos;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$new_pos</span> = <span style="color:#0000FF;">$cur_pos</span> + <span style="color:#0000FF;">$n_steps</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$n_steps</span> &amp;lt;<span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$min_pos</span> = <span style="color:#0000FF;">$cur_pos</span> + <span style="color:#0000FF;">$n_steps</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$max_pos</span> = <span style="color:#0000FF;">$cur_pos</span> - <span style="color:#CC66CC;color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$shift_sign</span> = <span style="color:#FF0000;">'+'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$n_steps</span>&amp;gt; <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$min_pos</span> = <span style="color:#0000FF;">$cur_pos</span> + <span style="color:#CC66CC;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$max_pos</span> = <span style="color:#0000FF;">$cur_pos</span> + <span style="color:#0000FF;">$n_steps</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$shift_sign</span> = <span style="color:#FF0000;">'-'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">return</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$id</span> = <span style="color:#0000FF;">$this</span>-&amp;gt;id;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Reorder existing items that will be existed by moving this item</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$sql</span> = <span style="color:#FF0000;">"UPDATE&nbsp; positions</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">SET&nbsp;&nbsp;order_num = order_num $shift_sign 1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">WHERE&nbsp; &nbsp;id = $id</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">AND&nbsp;position&amp;gt;= $min_pos</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">AND&nbsp;position &amp;lt;= $max_pos"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&amp;gt;db-&amp;gt;query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$sql</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Now set new position for this item</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$sql</span> = <span style="color:#FF0000;">"UPDATE postions SET position = $new_pos WHERE id = $id"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&amp;gt;db-&amp;gt;query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$sql</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/php-code-snippet-reorder-items-in-a-table/&via=vinoaj&text=PHP code snippet - Reorder items in a table&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/php-code-snippet-reorder-items-in-a-table/&via=vinoaj&text=PHP code snippet - Reorder items in a table&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F07%2Fphp-code-snippet-reorder-items-in-a-table%2F&amp;title=PHP%20code%20snippet%20%E2%80%93%20Reorder%20items%20in%20a%20table" id="wpa2a_10"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/07/php-code-snippet-reorder-items-in-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>svn &#8211; Ignore/exclude files from version control</title>
		<link>http://vinoaj.com/blog/2007/07/svn-ignoreexclude-files-from-version-control/</link>
		<comments>http://vinoaj.com/blog/2007/07/svn-ignoreexclude-files-from-version-control/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 10:34:13 +0000</pubDate>
		<dc:creator>vinoaj</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/svn-ignoreexclude-files-from-version-control/</guid>
		<description><![CDATA[In most projects there are going to be files that you wish to ignore in version control. These could be temporary files, log or debug files, and so forth. These are files that you can safely ignore when executing commands such as svn commit and svn st. The following shows how to configure your svn [...]]]></description>
			<content:encoded><![CDATA[<p>In most projects there are going to be files that you wish to ignore in version control.  These could be temporary files, log or debug files, and so forth.  These are files that you can safely ignore when executing commands such as <code>svn commit</code> and <code>svn st</code>.  The following shows how to configure your svn client to ignore particular files in your working copy.</p>
<pre>svn propedit svn:ignore /path/with/files/to/ignore/</pre>
<p>svn opens up your text editor of choice</p>
<p>Use file patterns to indicate which files to ignore from version control. Each pattern goes on a new line. e.g.</p>
<pre>
log_12*.log
*.tmp</pre>
<p>Save your file and exit</p>
<p>Now whenever you perform commands like <code>svn st</code> or <code>svn commit</code>, svn will ignore files with the patterns you specified in the directories that you specified.</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/svn-ignoreexclude-files-from-version-control/&via=vinoaj&text=svn - Ignore/exclude files from version control&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/07/svn-ignoreexclude-files-from-version-control/&via=vinoaj&text=svn - Ignore/exclude files from version control&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F07%2Fsvn-ignoreexclude-files-from-version-control%2F&amp;title=svn%20%E2%80%93%20Ignore%2Fexclude%20files%20from%20version%20control" id="wpa2a_12"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/07/svn-ignoreexclude-files-from-version-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class Inheritance in Javascript</title>
		<link>http://vinoaj.com/blog/2007/06/class-inheritance-in-javascript/</link>
		<comments>http://vinoaj.com/blog/2007/06/class-inheritance-in-javascript/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 11:07:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[oo]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/class-inheritance-in-javascript/</guid>
		<description><![CDATA[My previous post showed how to create classes in Javascript. This addendum post shows how to create an inherited class from a parent class. The concept is simple. Declare and define your parent class Declare and define your child class without defining the parent-child relationship Add a new instance of your parent class to your [...]]]></description>
			<content:encoded><![CDATA[<p>My previous post <a href="http://vinoaj.com/blog/howtos/creating-classes-with-javascript/">showed how to create classes in Javascript</a>.  This addendum post shows how to create an inherited class from a parent class.</p>
<p>The concept is simple.</p>
<ol>
<li>Declare and define your parent class</li>
<li>Declare and define your child class <strong>without</strong> defining the parent-child relationship</li>
<li>Add a new instance of your parent class to your child class' prototype.  Now the child class has access to the parent class' properties and methods.  This last step may seem counter-intuitive, but the example below helps to clarify what I mean.</li>
</ol>
<div class="igBar"><span id="ljavascript-15"><a href="#" onclick="javascript:showPlainTxt('javascript-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-15">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> SuperHero<span style="color: #66cc66;">&#40;</span>heroID, p1, p2, p3<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ...</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ...</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">/* Do some extending of SuperHero's prototype here */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">//Now let's define our child class - note that we do not initially define the parent-child relationship</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> AlienSuperHero<span style="color: #66cc66;">&#40;</span>heroID, homePlanet, race, p1, p2, p3<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//Now we indicate the parent-child relationship</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">prototype</span> = <span style="color: #003366; font-weight: bold;">new</span> SuperHero<span style="color: #66cc66;">&#40;</span>heroID, p1, p2, p3<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">/* Do some extending of AlienSuperHero's prototype here */</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Usage would be along the lines of:</p>
<div class="igBar"><span id="ljavascript-16"><a href="#" onclick="javascript:showPlainTxt('javascript-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-16">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> MartianManhunter = <span style="color: #003366; font-weight: bold;">new</span> AlienSuperHero<span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;color:#800000;">3454</span>, <span style="color: #3366CC;">'Mars'</span>, <span style="color: #3366CC;">'Martian'</span>, <span style="color: #3366CC;">'Flight'</span>, <span style="color: #3366CC;">'Telepathy'</span>, <span style="color: #3366CC;">'Shapeshifting'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>fire<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//This is a method defined in the parent class</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; MartianManhunter.<span style="color: #006600;">losePowers</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/06/class-inheritance-in-javascript/&via=vinoaj&text=Class Inheritance in Javascript&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/06/class-inheritance-in-javascript/&via=vinoaj&text=Class Inheritance in Javascript&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F06%2Fclass-inheritance-in-javascript%2F&amp;title=Class%20Inheritance%20in%20Javascript" id="wpa2a_14"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/06/class-inheritance-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating classes with Javascript</title>
		<link>http://vinoaj.com/blog/2007/06/creating-classes-with-javascript/</link>
		<comments>http://vinoaj.com/blog/2007/06/creating-classes-with-javascript/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 10:51:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[oo]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/creating-classes-with-javascript/</guid>
		<description><![CDATA[Javascript is a prototype-based language rather than a class-based language (e.g. Java). For an explanation of the difference, see Mozilla's comparison of class-based and prototype-based languages. In short, in a class-based language, objects are created by instantiating classes. The classes' list of properties and methods cannot be altered (e.g. added to) at runtime. A prototype-based [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript is a prototype-based language rather than a class-based language (e.g. Java).  For an explanation of the difference, see Mozilla's <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Class-Based_vs._Prototype-Based_Languages" target="_blank">comparison of class-based and prototype-based languages</a>.  </p>
<p>In short, in a class-based language, objects are created by instantiating classes.  The classes' list of properties and methods cannot be altered (e.g. added to) at runtime.  A prototype-based language does not have the notion of a class.  Everything is an object.  A prototype-based object can have its list of properties and methods modified during runtime.</p>
<p>The examples below show how to create a class in Javascript.  First we define a function that will behave as our constructor.  Then we extend that function's prototype to include further functions that will behave as the class' methods.  Note the use of the &quot;this&quot; keyword to refer to the prototype of the current object.</p>
<div class="igBar"><span id="ljavascript-19"><a href="#" onclick="javascript:showPlainTxt('javascript-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-19">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">//This is our constructor</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> SuperHero<span style="color: #66cc66;">&#40;</span>heroID, p1, p2, p3<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">heroID</span> = heroID;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_1</span> = p1;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_2</span> = p2;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_3</span> = p3;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_ultimate</span> = p1 + p2 + p3;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">//Now add some methods to the class</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SuperHero.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">getPower1</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SuperHero.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">losePowers</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_1</span> = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_2</span> = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">power_3</span> = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SuperHero.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">setName</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">name</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> = <span style="color: #000066;">name</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SuperHero.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">alertProfile</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> str = <span style="color: #3366CC;">'Hero Profile:<span style="color: #000099; font-weight: bold;">\n</span>'</span> +</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #3366CC;">'Name: '</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> + <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> +</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #3366CC;">'Name: '</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> + <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> +</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #3366CC;">'Name: '</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> + <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> +</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #3366CC;">'Name: '</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> + <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> +</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>And now we have a simple class with a few simple properties and methods.  Usage of the class would be something like:</p>
<div class="igBar"><span id="ljavascript-20"><a href="#" onclick="javascript:showPlainTxt('javascript-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-20">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> Superman = <span style="color: #003366; font-weight: bold;">new</span> SuperHero<span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;color:#800000;">2331</span>, <span style="color: #3366CC;">'Flight'</span>, <span style="color: #3366CC;">'Speed'</span>, <span style="color: #3366CC;">'Strength'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Superman.<span style="color: #006600;">setName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Superman: Man of Steel'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> power_1&nbsp; = Superman.<span style="color: #006600;">getPower1</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>kryptonite<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Superman.<span style="color: #006600;">losePowers</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Superman.<span style="color: #006600;">alertProfile</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/06/creating-classes-with-javascript/&via=vinoaj&text=Creating classes with Javascript&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/06/creating-classes-with-javascript/&via=vinoaj&text=Creating classes with Javascript&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F06%2Fcreating-classes-with-javascript%2F&amp;title=Creating%20classes%20with%20Javascript" id="wpa2a_16"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/06/creating-classes-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Akismet and PHP for your site</title>
		<link>http://vinoaj.com/blog/2007/05/akismet-and-php-for-your-site/</link>
		<comments>http://vinoaj.com/blog/2007/05/akismet-and-php-for-your-site/#comments</comments>
		<pubDate>Tue, 15 May 2007 11:13:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/akismet-and-php-for-your-site/</guid>
		<description><![CDATA[A few sites I administer have recently had the misfortune of having spambots visit their enquiry and contact pages. These pages usually have a contact form, where an enquirer can leave their name, e-mail, and request or comment. When they submit the form, a copy of the message is e-mailed to the site owner. The [...]]]></description>
			<content:encoded><![CDATA[<p>A few sites I administer have recently had the misfortune of having spambots visit their enquiry and contact pages.  These pages usually have a contact form, where an enquirer can leave their name, e-mail, and request or comment.  When they submit the form, a copy of the message is e-mailed to the site owner.  The spambots try and submit messages that usually contain gibberish but also multiple URLs to spam sites.  Something had to be done to prevent site owners from receiving hundreds of spam messages a day.</p>
<p>I considered a few methods for preventing the bots from visiting the enquiry page.  These included firewall configuration, user-agent detection, rudimentary parsing of the messages, captcha systems, and so forth.  These methods were either too cumbersome to implement, could be circumvented, or spoiled the user experience for a genuine user.  The latter was a critical concern.</p>
<h2>Enter Akismet</h2>
<p>The Akismet API is an open API used to assess the spam score of comments left or enquiries made on a site.  It is in widespread use as a plugin for WordPress blogs.  Its effectiveness has become a must-have plugin for WordPress installations.  The Akismet API however can be applied to any site or application capable of making HTTP requests.</p>
<p>First you need an API key.  You can obtain one by <a href="http://wordpress.com/signup/" target="_blank">registering for a WordPress.com user account</a> (you do not need to have an active WordPress blog).  Your API key will be e-mailed to you once you have activated your account.</p>
<h2>Akismet and PHP5</h2>
<p><a href="http://www.achingbrain.net/stuff/akismet/#download" target="_blank">Download the PHP5 Akismet Library</a>.<br />
Extract the contents of the downloaded package and place them in a location that your application can access when required.</p>
<p>Here's how to use the Akismet API in your PHP5 code.</p>
<div class="igBar"><span id="lphp-23"><a href="#" onclick="javascript:showPlainTxt('php-23'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-23">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require_once</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Akismet.class.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$API_key</span> = <span style="color:#FF0000;">'xxxxxxxxxxxx'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$source_url</span> = <span style="color:#FF0000;">'http://www.mysite.com/contact.php'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span> = <span style="color:#000000; font-weight:bold;">new</span> Akismet<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$source_url</span>, <span style="color:#0000FF;">$API_key</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">setCommentAuthor</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$enquirer_name</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">setCommentAuthorEmail</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$enquirer_email</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">setCommentContent</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$enquiry</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">isCommentSpam</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//Enquiry is spammy - log it for later review by site owner</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//If false positive, be sure to submit to Akismet so that it can learn from</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; its mistake.&nbsp; Use Akismet::submitHam()</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//Enquiry is not spammy - e-mail it to the site owner</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//If false, be sure to submit to Akismet so that it can train itself better.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; Use Akismet::submitSpam()</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Below are other Akismet methods that you could call</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">setCommentAuthorURL</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$enquirer_url</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">setCommentType</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$enquiry_type</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//{'blank', 'comment', 'trackback', 'pingback', or custom}</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">setPermalink</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; &nbsp;<span style="color:#FF9933; font-style:italic;">//A permanent URL referencing the resource for which a comment is being left for </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h2>Akismet and PHP4</h2>
<p><a href="http://www.miphp.net/blog/view/php4_akismet_class/" target="_blank">Download the PHP4 Akismet library</a>.  Extract the contents of the downloaded package and place them in a location that your application can access when required.</p>
<p>Here's how to use the Akismet API in your PHP4 code.</p>
<div class="igBar"><span id="lphp-24"><a href="#" onclick="javascript:showPlainTxt('php-24'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-24">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require_once</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Akismet.class.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$API_key</span> = <span style="color:#FF0000;">'xxxxxxxxxxxx'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$source_url</span> = <span style="color:#FF0000;">'http://www.mysite.com/contact.php'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$comment</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'author'</span> &nbsp; &nbsp; =&gt; <span style="color:#0000FF;">$enquirer_name</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color:#FF0000;">'email'</span>&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span style="color:#0000FF;">$enquirer_email</span>, </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color:#FF0000;">'website'</span> &nbsp;&nbsp;=&gt; <span style="color:#0000FF;">$enquirer_uri</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color:#FF0000;">'body'</span> &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span style="color:#0000FF;">$enquiry</span>, </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color:#FF0000;">'permalink'</span>&nbsp; &nbsp; =&gt; <span style="color:#0000FF;">$this_page_uri</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color:#FF0000;">'user_ip'</span> &nbsp;&nbsp;=&gt; <span style="color:#0000FF;">$referrer_ip</span>, &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// optional, defaults to $_SERVER['REMOTE_ADDR'] </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color:#FF0000;">'user_agent'</span> &nbsp; =&gt; <span style="color:#0000FF;">$client_ua</span>,&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// optional, defaults to $_SERVER['HTTP_USER_AGENT']</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$akismet</span> = <span style="color:#000000; font-weight:bold;">new</span> Akismet<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$source_url</span>, <span style="color:#0000FF;">$API_key</span>, <span style="color:#0000FF;">$comment</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// test for errors before submitting to Akismet </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">errorsExist</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">isError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'AKISMET_INVALID_KEY'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//...</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">isError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'AKISMET_RESPONSE_FAILED'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//...</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">isError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'AKISMET_SERVER_NOT_FOUND'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//...</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$akismet</span>-&gt;<span style="color:#006600;">isSpam</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//Enquiry is spammy - log it for later review by site owner</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//If false positive, be sure to submit to Akismet so that it can learn from</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; its mistake.&nbsp; Use Akismet::submitHam()</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//Enquiry is not spammy - e-mail it to the site owner</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//If false, be sure to submit to Akismet so that it can train itself better.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; Use Akismet::submitSpam()</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/05/akismet-and-php-for-your-site/&via=vinoaj&text=Akismet and PHP for your site&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/05/akismet-and-php-for-your-site/&via=vinoaj&text=Akismet and PHP for your site&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F05%2Fakismet-and-php-for-your-site%2F&amp;title=Akismet%20and%20PHP%20for%20your%20site" id="wpa2a_18"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/05/akismet-and-php-for-your-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Timezones and UTC in PHP</title>
		<link>http://vinoaj.com/blog/2007/05/timezones-and-utc-in-php/</link>
		<comments>http://vinoaj.com/blog/2007/05/timezones-and-utc-in-php/#comments</comments>
		<pubDate>Tue, 08 May 2007 20:44:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/timezones-and-utc-in-php/</guid>
		<description><![CDATA[If you are dealing with multiple users in different timezones or simply want to display times in a timezone other than your server's settings, it is best to store timestamps as their UTC (~ GMT) equivalents. When you read those timestamps later, you can convert them to local time. Local time to UTC time PLAIN [...]]]></description>
			<content:encoded><![CDATA[<p>If you are dealing with multiple users in different timezones or simply want to display times in a timezone other than your server's settings, it is best to store timestamps as their UTC (~ GMT) equivalents.  When you read those timestamps later, you can convert them to local time.</p>
<h2>Local time to UTC time</h2>
<div class="igBar"><span id="lphp-27"><a href="#" onclick="javascript:showPlainTxt('php-27'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-27">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">date_default_timezone_set<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Australia/Sydney'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$time</span> = <a href="http://www.php.net/gmmktime"><span style="color:#000066;">gmmktime</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$hr</span>, <span style="color:#0000FF;">$min</span>, <span style="color:#0000FF;">$sec</span>, <span style="color:#0000FF;">$mon</span>, <span style="color:#0000FF;">$day</span>, <span style="color:#0000FF;">$yr</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$date</span> = <a href="http://www.php.net/gmdate"><span style="color:#000066;">gmdate</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'d/m/Y H:i'</span>, <a href="http://www.php.net/time"><span style="color:#000066;">time</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><code>date_default_timezone_set</code> sets the default timezone for all date &amp; time operations.<br />
<code>gmmktime</code> is analogous to <code>mktime</code> except it takes in <strong>local time values</strong> and creates the corresponding UTC timestamp.<br />
<code>gmdate</code> similarly takes in local time values and creates the corresponding UTC date &amp; time.</p>
<h2>UTC time to Local time</h2>
<div class="igBar"><span id="lphp-28"><a href="#" onclick="javascript:showPlainTxt('php-28'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-28">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ts_utc</span> = read_timestamp_from_db<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp;<span style="color:#FF9933; font-style:italic;">//Some custom function in your script</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">date_default_timezone_set<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Australia/Sydney'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$offset</span> = <a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Z'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//Timezone offset from UTC in number of seconds (can be +ve or -ve)</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ts_local</span> = <span style="color:#0000FF;">$ts_utc</span> + <span style="color:#0000FF;">$offset</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/05/timezones-and-utc-in-php/&via=vinoaj&text=Timezones and UTC in PHP&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/05/timezones-and-utc-in-php/&via=vinoaj&text=Timezones and UTC in PHP&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F05%2Ftimezones-and-utc-in-php%2F&amp;title=Timezones%20and%20UTC%20in%20PHP" id="wpa2a_20"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/05/timezones-and-utc-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent caching of page on client&#8217;s end &#8211; PHP and HTML solutions</title>
		<link>http://vinoaj.com/blog/2007/05/prevent-caching-of-page-on-clients-end-php-and-html-solutions/</link>
		<comments>http://vinoaj.com/blog/2007/05/prevent-caching-of-page-on-clients-end-php-and-html-solutions/#comments</comments>
		<pubDate>Sun, 06 May 2007 00:48:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/prevent-caching-of-page-on-clients-end-php-and-html-solutions/</guid>
		<description><![CDATA[To prevent the caching of a web page on your client's end, use the following snippet of PHP to ensure that the appropriate HTTP headers are sent. PLAIN TEXT PHP: header&#40;"Cache-Control: no-cache, must-revalidate"&#41;; // HTTP/1.1 header&#40;"Expires: Tue, 03 Jul 1979 00:00:00 GMT"&#41;;&#160; &#160;// Date in the past The first header tells the client that the [...]]]></description>
			<content:encoded><![CDATA[<p>To prevent the caching of a web page on your client's end, use the following snippet of PHP to ensure that the appropriate HTTP headers are sent.</p>
<div class="igBar"><span id="lphp-31"><a href="#" onclick="javascript:showPlainTxt('php-31'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-31">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Cache-Control: no-cache, must-revalidate"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// HTTP/1.1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Expires: Tue, 03 Jul 1979 00:00:00 GMT"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; &nbsp;<span style="color:#FF9933; font-style:italic;">// Date in the past </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The first header tells the client that the page must not be cached.<br />
The second header is a backup, and tells the client that the page expired a long time ago in the past, and it should fetch a more recent version.</p>
<p>The same effect can be achieved by placing corresponding meta tags in your HTML document</p>
<div class="igBar"><span id="lhtml-32"><a href="#" onclick="javascript:showPlainTxt('html-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-32">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Expires"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"Tue, 03 Jul 1979 00:00:00 GMT"</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Pragma"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"no-cache"</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></a></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Where possible, place your cache control directives in the HTTP header, because some clients and proxies rely on your server's HTTP response to determine caching.</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/05/prevent-caching-of-page-on-clients-end-php-and-html-solutions/&via=vinoaj&text=Prevent caching of page on client's end - PHP and HTML solutions&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/05/prevent-caching-of-page-on-clients-end-php-and-html-solutions/&via=vinoaj&text=Prevent caching of page on client's end - PHP and HTML solutions&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F05%2Fprevent-caching-of-page-on-clients-end-php-and-html-solutions%2F&amp;title=Prevent%20caching%20of%20page%20on%20client%E2%80%99s%20end%20%E2%80%93%20PHP%20and%20HTML%20solutions" id="wpa2a_22"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/05/prevent-caching-of-page-on-clients-end-php-and-html-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using mysqldump to export a database</title>
		<link>http://vinoaj.com/blog/2007/04/using-mysqldump-to-export-a-database/</link>
		<comments>http://vinoaj.com/blog/2007/04/using-mysqldump-to-export-a-database/#comments</comments>
		<pubDate>Sat, 28 Apr 2007 05:07:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/using-mysqldump-to-export-a-database/</guid>
		<description><![CDATA[mysqldump is a useful utility for dumping the contents of an entire database to an SQL file. PLAIN TEXT CODE: mysqldump --user=dbusername --password=dbpassword db_name_here&#38;gt; db_name_here.sql By default the --opt option is enabled, which is a shorthand option for specifying the below options. According to the documentation, using this option "... should give you a fast [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html" target="_blank">mysqldump</a> is a useful utility for dumping the contents of an entire database to an SQL file.</p>
<div class="igBar"><span id="lcode-35"><a href="#" onclick="javascript:showPlainTxt('code-35'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-35">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysqldump --user=dbusername --password=dbpassword db_name_here&amp;gt; db_name_here.<span style="">sql</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>By default the <code>--opt</code> option is enabled, which is a shorthand option for specifying the below options.  According to the documentation, using this option "... should give you a fast dump operation and produce a dump file that can be reloaded into a MySQL server quickly".</p>
<div class="igBar"><span id="lcode-36"><a href="#" onclick="javascript:showPlainTxt('code-36'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-36">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--add-drop-table</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--add-locks</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--create-options</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--disable-keys</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--extended-insert</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--lock-tables</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--quick</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--set-charset </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/using-mysqldump-to-export-a-database/&via=vinoaj&text=Using mysqldump to export a database&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/using-mysqldump-to-export-a-database/&via=vinoaj&text=Using mysqldump to export a database&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F04%2Fusing-mysqldump-to-export-a-database%2F&amp;title=Using%20mysqldump%20to%20export%20a%20database" id="wpa2a_24"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/04/using-mysqldump-to-export-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP/CURL</title>
		<link>http://vinoaj.com/blog/2007/04/phpcurl/</link>
		<comments>http://vinoaj.com/blog/2007/04/phpcurl/#comments</comments>
		<pubDate>Fri, 20 Apr 2007 23:35:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[curl]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/howtos/phpcurl/</guid>
		<description><![CDATA[cURL is used to interact with remote URLs without needing a user to initiate the process (e.g. by clicking on a form submit button). cURL is useful for submitting HTTP POST/PUT/DELETE requests when dealing with web services. PHP has inbuilt cURL support since PHP 4.0.2 using cURL's libcurl library. Find out more about PHP/CURL -- [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://curl.haxx.se/" target="_blank">cURL</a> is used to interact with remote URLs without needing a user to initiate the process (e.g. by clicking on a form submit button).  cURL is useful for submitting HTTP POST/PUT/DELETE requests when dealing with web services.  PHP has inbuilt cURL support since PHP 4.0.2 using cURL's libcurl library.  Find out more about <a href="http://curl.haxx.se/libcurl/php/" target="_blank">PHP/CURL -- using libcurl with PHP here</a>.</p>
<p>A fullset of cURL options and what they mean can be found in<br />
<a href="http://au3.php.net/manual/en/function.curl-setopt.php" target="_blank">PHP's manual entry for curl_setopt()</a>.</p>
<div class="igBar"><span id="lphp-38"><a href="#" onclick="javascript:showPlainTxt('php-38'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-38">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Contains encoded string to pass along for basic authentication purposes</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$auth_token</span> = <a href="http://www.php.net/base64_encode"><span style="color:#000066;">base64_encode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$username</span> . <span style="color:#FF0000;">'-'</span> . <span style="color:#0000FF;">$password</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Target URL - the URL you want to submit a form to</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$target_url</span> = <span style="color:#FF0000;">'http://www.remotesite.com/post_target.php'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Create&nbsp; a new cURL handle</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Passing the target URL to curl_init allows you to bypass the call curl_setopt($ch, CURLOPT_URL, $target_url);</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ch</span> = curl_init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$target_url</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Tell the handler that the info is to be sent using an HTTP POST request</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_POST, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Set other relevant headers.&nbsp; Place each header as an array element</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//An alternative to building the Authorization header is to use curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$headers</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Authorization: Basic '</span> . <span style="color:#0000FF;">$auth_token</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color:#FF0000;">'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_HTTPHEADER, <span style="color:#0000FF;">$headers</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Pass the POST fields - be sure to urlencode your value strings (hint: http_build_query() will do this for you; PHP5)</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Below we assume values have already been posted to this script and kept in $_POST.&nbsp; We have validated the submission and</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// are now posting the same values to a remote URL</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_POSTFIELDS, http_build_query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//When we execute the handle, we want curl_exec() to return to a string rather than directly outputting it</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_RETURNTRANSER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Don't use a cached connection - explicitly create a new one</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_FRESH_CONNECT, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Fail if cannot connect to the target server within 5 seconds</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_CONNECTTIMEOUT, <span style="color:#CC66CC;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//If the target server returns a redirect request using the &quot;Location:&quot; header directive, then follow it.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//To prevent recursive redirects, only do a max of 5 follows</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_FOLLOWLOCATION, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_MAXREDIRS, <span style="color:#CC66CC;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Let's now execute the handler</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Because CURLOPT_RETURNTRANSFER is true, we need to capture the return value of curl_exec()</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$response_data</span> = curl_exec<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Was there an error?</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//curl_errno() returns the error code</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//curl_error() returns a clear text message for the last cURL operation</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>curl_errno<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/die"><span style="color:#000066;">die</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'There was a cURL error: '</span> . curl_error<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//Close the handler and release resources</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; curl_close<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Now do something with your data</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">return</span> myProcessingFunction<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/phpcurl/&via=vinoaj&text=PHP/CURL&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/phpcurl/&via=vinoaj&text=PHP/CURL&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F04%2Fphpcurl%2F&amp;title=PHP%2FCURL" id="wpa2a_26"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/04/phpcurl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rewriting URLs to force www or non-www URLs</title>
		<link>http://vinoaj.com/blog/2007/04/rewriting-urls-to-force-www-or-non-www-urls/</link>
		<comments>http://vinoaj.com/blog/2007/04/rewriting-urls-to-force-www-or-non-www-urls/#comments</comments>
		<pubDate>Thu, 12 Apr 2007 21:25:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/uncategorized/rewriting-urls-to-force-www-or-non-www-urls/</guid>
		<description><![CDATA[PLAIN TEXT CODE: #Activate the rewrite engine if it isn't so already RewriteEngine on #intercept all HTTP requests to the site that do not have a 'www.' at the beginning of the Domain name #and then force a redirect to the same page address only this time, including the 'www.' RewriteCond %{HTTP_HOST} !^www\..* [NC] RewriteRule [...]]]></description>
			<content:encoded><![CDATA[<div class="igBar"><span id="lcode-40"><a href="#" onclick="javascript:showPlainTxt('code-40'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-40">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#Activate the rewrite engine if it isn<span style="color:#CC0000;">'t so already</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">RewriteEngine on</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"></li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">#intercept all HTTP requests to the site that do not have a '</span>www.<span style="color:#CC0000;">' at the beginning of the Domain name</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">#and then force a redirect to the same page address only this time, including the '</span>www.<span style="color:#CC0000;">'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">RewriteCond %{HTTP_HOST} !^www<span style="color:#000099; font-weight:bold;">\.</span>.* [NC]</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]</span></div>
</li>
<li style="font-weight: bold;color:#26536A;"></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">#The inverse of the above rule - intercept HTTP requests with a '</span>www.<span style="color:#CC0000;">' at the start and redirect to the non-www version</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;"># Ensure that your serverName directive is set up to the non-www name of your domain</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">RewriteCond %{HTTP_HOST} ^www<span style="color:#000099; font-weight:bold;">\.</span>.* [NC]</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">RewriteRule ^(.*) http://%{SERVER_NAME}/$1 [R=301] </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/rewriting-urls-to-force-www-or-non-www-urls/&via=vinoaj&text=Rewriting URLs to force www or non-www URLs&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/rewriting-urls-to-force-www-or-non-www-urls/&via=vinoaj&text=Rewriting URLs to force www or non-www URLs&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F04%2Frewriting-urls-to-force-www-or-non-www-urls%2F&amp;title=Rewriting%20URLs%20to%20force%20www%20or%20non-www%20URLs" id="wpa2a_28"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/04/rewriting-urls-to-force-www-or-non-www-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending a plain text e-mail</title>
		<link>http://vinoaj.com/blog/2007/04/sending-a-plain-text-e-mail/</link>
		<comments>http://vinoaj.com/blog/2007/04/sending-a-plain-text-e-mail/#comments</comments>
		<pubDate>Thu, 12 Apr 2007 21:04:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://vinoaj.com/blog/uncategorized/sending-a-plain-text-e-mail/</guid>
		<description><![CDATA[Sending a plain-text e-mail through PHP is a simple process PLAIN TEXT PHP: mail &#40;$to, $subject, $message, $headers&#41;; The $to parameter can look like: example@mysite.com example@mysite.com, user@mysite.com Example Sr &#60;example@mysite.com&#62;, Example Jr &#60;user@mysite.com&#62; Common headers to use in your messages: PLAIN TEXT PHP: $headers = &#160;"From: yourname@yoursite.com\r\n &#160; &#160; &#160; &#160; &#160; &#160;&#160; Reply-To: replyhere@yoursite.com\r\n [...]]]></description>
			<content:encoded><![CDATA[<p>Sending a plain-text e-mail through PHP is a simple process</p>
<div class="igBar"><span id="lphp-43"><a href="#" onclick="javascript:showPlainTxt('php-43'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-43">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/mail"><span style="color:#000066;">mail</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$to</span>, <span style="color:#0000FF;">$subject</span>, <span style="color:#0000FF;">$message</span>, <span style="color:#0000FF;">$headers</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The $to parameter can look like:</p>
<pre>
example@mysite.com
example@mysite.com, user@mysite.com
Example Sr &lt;example@mysite.com&gt;, Example Jr &lt;user@mysite.com&gt;
</pre>
<p>Common headers to use in your messages:</p>
<div class="igBar"><span id="lphp-44"><a href="#" onclick="javascript:showPlainTxt('php-44'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-44">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$headers</span> = &nbsp;<span style="color:#FF0000;">"From: yourname@yoursite.com<span style="color:#000099; font-weight:bold;">\r</span><span style="color:#000099; font-weight:bold;">\n</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Reply-To: replyhere@yoursite.com<span style="color:#000099; font-weight:bold;">\r</span><span style="color:#000099; font-weight:bold;">\n</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Cc: watcher@yoursite.com<span style="color:#000099; font-weight:bold;">\r</span><span style="color:#000099; font-weight:bold;">\n</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Bcc: spy@yoursite.com<span style="color:#000099; font-weight:bold;">\r</span><span style="color:#000099; font-weight:bold;">\n</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; X-Mailer: YourApplicationNameHere<span style="color:#000099; font-weight:bold;">\r</span><span style="color:#000099; font-weight:bold;">\n</span>"</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/sending-a-plain-text-e-mail/&via=vinoaj&text=Sending a plain text e-mail&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://vinoaj.com/blog/2007/04/sending-a-plain-text-e-mail/&via=vinoaj&text=Sending a plain text e-mail&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fvinoaj.com%2Fblog%2F2007%2F04%2Fsending-a-plain-text-e-mail%2F&amp;title=Sending%20a%20plain%20text%20e-mail" id="wpa2a_30"><img src="http://vinoaj.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://vinoaj.com/blog/2007/04/sending-a-plain-text-e-mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

