<?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>XEWeb</title>
	<atom:link href="http://www.xeweb.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xeweb.net</link>
	<description>XEWeb blog, PHP scripts and more...</description>
	<lastBuildDate>Mon, 22 Mar 2010 16:32:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Thumbnail opacity hover with CSS and jQuery</title>
		<link>http://www.xeweb.net/2010/03/22/thumbnail-opacity-hover-with-css-and-jquery/</link>
		<comments>http://www.xeweb.net/2010/03/22/thumbnail-opacity-hover-with-css-and-jquery/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 16:32:38 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=123</guid>
		<description><![CDATA[A nice effect when hovering over thumbnails is to change the opacity, so that it has that fade in and out effect. &#60;ul class=&#34;thumbnails&#34;&#62; &#160;&#60;li&#62;&#60;a href=&#34;#&#34;&#62;&#60;img src=&#34;thumb-1.jpg&#34; alt=&#34;&#34; /&#62;&#60;/a&#62;&#60;/li&#62; &#160;&#60;li&#62;&#60;a href=&#34;#&#34;&#62;&#60;img src=&#34;thumb-2.jpg&#34; alt=&#34;&#34; /&#62;&#60;/a&#62;&#60;/li&#62; &#160;&#60;li&#62;&#60;a href=&#34;#&#34;&#62;&#60;img src=&#34;thumb-3.jpg&#34; alt=&#34;&#34; /&#62;&#60;/a&#62;&#60;/li&#62; &#160;&#60;li&#62;&#60;a href=&#34;#&#34;&#62;&#60;img src=&#34;thumb-4.jpg&#34; alt=&#34;&#34; /&#62;&#60;/a&#62;&#60;/li&#62; &#160;&#60;li&#62;&#60;a href=&#34;#&#34;&#62;&#60;img src=&#34;thumb-5.jpg&#34; alt=&#34;&#34; /&#62;&#60;/a&#62;&#60;/li&#62; &#60;/ul&#62; Take the above example, a [...]]]></description>
			<content:encoded><![CDATA[<p>A nice effect when hovering over thumbnails is to change the opacity, so that it has that fade in and out effect.</p>
<div class="html4strict geshi no html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumbnails&quot;</span>&gt;</span><br />
&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb-1.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb-2.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb-3.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb-4.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb-5.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></div>
<p>Take the above example, a simple list of images. Let&#8217;s apply the basic styling for it&#8230;</p>
<div class="css geshi no css" style="font-family:monospace;">ul<span style="color: #6666ff;">.thumbnails</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
ul<span style="color: #6666ff;">.thumbnails</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
ul<span style="color: #6666ff;">.thumbnails</span> li img <span style="color: #00AA00;">&#123;</span> filter<span style="color: #00AA00;">:</span> alpha<span style="color: #00AA00;">&#40;</span>opacity<span style="color: #00AA00;">=</span><span style="color: #cc66cc;">60</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* IE only */</span> opacity<span style="color: #00AA00;">:</span> .60<span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* All other browsers */</span> <span style="color: #00AA00;">&#125;</span></div>
<p>As you can see all of the thumbnails will have a default opacity of 60%. Now comes the jQuery script to add the fade effect&#8230;</p>
<div class="javascript geshi no javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;ul.thumbnails li&#39;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;img&#39;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;img&#39;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">0.6</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
<p>And that&#8217;s all there is to it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/03/22/thumbnail-opacity-hover-with-css-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pure CSS coke can spin</title>
		<link>http://www.xeweb.net/2010/02/20/pure-css-coke-can-spin/</link>
		<comments>http://www.xeweb.net/2010/02/20/pure-css-coke-can-spin/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 10:40:51 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=121</guid>
		<description><![CDATA[This just goes to show what you can do with CSS these days as Rom&#225;n Cort&#233;s demonstrates with his awesome spinning coke can example. I found out that by a combination of the CSS1 properties background-attachment and background-position, 2D displacement maps could be created and, by scrolling, the displacement map would be applied to different [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.xeweb.net/wp-content/uploads/css-coke-can.jpg" alt="Pure CSS coke can spin" width="180" height="134" class="alignleft size-full wp-image-122" />This just goes to show what you can do with CSS these days as Rom&aacute;n Cort&eacute;s demonstrates with his awesome spinning coke can example.</p>
<blockquote><p>I found out that by a combination of the CSS1 properties background-attachment  and background-position, 2D displacement maps could be created and, by scrolling, the displacement map would be applied to different parts of the texture (a background image).</p>
<p>With displacement maps lots of cool effects could be done, but thinking that the complexity of the displacement map would directly affect the CSS and markup size, choosing a good example took me some time. I thought in sea waves reflections, underwater distortions, magnifying glass, a rotating Earth… but the final thing I did was just right in my desktop: a Coke can &#8211; my favourite drink.</p>
<p>Due the cilindrical shape of a can, the displacement map is very simple with the parallel projection I did, so the code is very little &#8211; below 5kb &#8211; and easy to understand I hope.</p>
<p>Even if this effect is mainly CSS1 and some bits of CSS2 &#8211; for the scrolling div, overflow: auto property -, it is not going to work in IE6, because it doesn’t support background-attachment: fixed. I’ve tested it and it works in IE8, Firefox 3.5, Chrome 3, Safari 4 and Opera 10. Also, the code validates.</p></blockquote>
<p>Check it out at <a href="http://www.romancortes.com/blog/pure-css-coke-can/">http://www.romancortes.com/blog/pure-css-coke-can/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/02/20/pure-css-coke-can-spin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D carousel using jQuery</title>
		<link>http://www.xeweb.net/2010/02/02/3d-carousel-using-jquery/</link>
		<comments>http://www.xeweb.net/2010/02/02/3d-carousel-using-jquery/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 16:47:12 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=119</guid>
		<description><![CDATA[Inspired by Andrew Sellick&#8217;s Simple 3D Carousel using Mootools I needed a jQuery version of the script, source code of which is below (tested with jQuery 1.4). Please refer to the original tutorial for instructions and a working demo. var count = 0; var baseSpeed = 0.05; var radiusX = 190; var radiusY = 40; [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.xeweb.net/wp-content/uploads/small-simple-3d-carousel-150x122.png" alt="3D carousel using jQuery" width="150" height="122" class="alignleft size-thumbnail wp-image-120" />Inspired by Andrew Sellick&#8217;s <a href="http://www.andrewsellick.com/75/simple-3d-carousel-using-mootools">Simple 3D Carousel using Mootools</a> I needed a jQuery version of the script, source code of which is below (tested with jQuery 1.4).</p>
<p>Please refer to the <a href="http://www.andrewsellick.com/75/simple-3d-carousel-using-mootools">original tutorial</a> for instructions and a working demo.</p>
<div class="javascript geshi no javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> count <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <br />
<span style="color: #003366; font-weight: bold;">var</span> baseSpeed <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.05</span><span style="color: #339933;">;</span> <br />
<span style="color: #003366; font-weight: bold;">var</span> radiusX <span style="color: #339933;">=</span> <span style="color: #CC0000;">190</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> radiusY <span style="color: #339933;">=</span> <span style="color: #CC0000;">40</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> centerX <span style="color: #339933;">=</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">;</span> <br />
<span style="color: #003366; font-weight: bold;">var</span> centerY <span style="color: #339933;">=</span> <span style="color: #CC0000;">190</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.3</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> imageDivs <span style="color: #339933;">=</span> <span style="color: #3366CC;">&#39;&#39;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> numberOfElements <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> carousel <span style="color: #339933;">=</span> <span style="color: #3366CC;">&#39;&#39;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> speedTest <span style="color: #339933;">=</span> <span style="color: #3366CC;">&#39;&#39;</span><span style="color: #339933;">;</span></p>
<p>$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <br />
&nbsp;carousel <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;#carousel&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;imageDivs <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;#carousel div&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;numberOfElements <span style="color: #339933;">=</span> imageDivs.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> </p>
<p>&nbsp;setInterval<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;startCarousel()&#39;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp;carousel.<span style="color: #660066;">mousemove</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; tempX <span style="color: #339933;">=</span> event.<span style="color: #660066;">clientX</span><span style="color: #339933;">;</span><br />
&nbsp; speed <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>tempX <span style="color: #339933;">-</span> centerX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2500</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #003366; font-weight: bold;">function</span> startCarousel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp;<br />
&nbsp;<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> numberOfElements<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></p>
<p>&nbsp; angle <span style="color: #339933;">=</span> i <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> numberOfElements<span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; posX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span> count <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> baseSpeed <span style="color: #339933;">*</span> speed <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> angle <span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span> radiusX <span style="color: #339933;">+</span> centerX <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; posY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span> count <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> baseSpeed <span style="color: #339933;">*</span> speed <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> angle <span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span> radiusY <span style="color: #339933;">+</span> centerY <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; imageDivWidth <span style="color: #339933;">=</span> posY<span style="color: #339933;">/</span><span style="color: #CC0000;">3</span><span style="color: #339933;">;</span><br />
&nbsp; imageDivZIndex <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>imageDivWidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">100</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;#carousel div&#39;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&#39;position&#39;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&#39;absolute&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;left&#39;</span><span style="color: #339933;">:</span> posX <span style="color: #339933;">+</span> <span style="color: #3366CC;">&#39;px&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;top&#39;</span><span style="color: #339933;">:</span> posY <span style="color: #339933;">+</span> <span style="color: #3366CC;">&#39;px&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;width&#39;</span><span style="color: #339933;">:</span> imageDivWidth <span style="color: #339933;">+</span> <span style="color: #3366CC;">&#39;px&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;zIndex&#39;</span><span style="color: #339933;">:</span> imageDivZIndex<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p>&nbsp; angle <span style="color: #339933;">+=</span> speed<span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;count<span style="color: #339933;">++;</span><br />
<span style="color: #009900;">&#125;</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/02/02/3d-carousel-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweet the Tube &#8211; Live train updates on twitter</title>
		<link>http://www.xeweb.net/2010/01/22/tweet-the-tube-live-train-updates-on-twitter/</link>
		<comments>http://www.xeweb.net/2010/01/22/tweet-the-tube-live-train-updates-on-twitter/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 12:56:38 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Company]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=118</guid>
		<description><![CDATA[I find it frustrating getting into London these days as there are always problems on the tube that causes delays. To take action we have launched a new service dubbed &#8220;Tweet the Tube&#8221; which provides live updates whenever a tube service changes status, pulled straight from the Transport for London website and checked every 5 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/tweetthetube"><img src="http://www.xeweb.net/wp-content/uploads/tweetthetube.jpg" alt="Tweet the Tube" width="200" height="200" class="alignleft size-full wp-image-116" /></a><br />
I find it frustrating getting into London these days as there are always problems on the tube that causes delays.</p>
<p>To take action we have launched a new service dubbed &#8220;Tweet the Tube&#8221; which provides live updates whenever a tube service changes status, pulled straight from the Transport for London website and checked every 5 minutes.</p>
<p>All you have to do is follow &#8220;tweetthetube&#8221; on twitter: <a href="http://twitter.com/tweetthetube">http://twitter.com/tweetthetube</a></p>
<p>Feel free to leave comments/suggestions on <a href="http://www.xeweb.net/tweet-the-tube/">this page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/01/22/tweet-the-tube-live-train-updates-on-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple PHP caching</title>
		<link>http://www.xeweb.net/2010/01/15/simple-php-caching/</link>
		<comments>http://www.xeweb.net/2010/01/15/simple-php-caching/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 15:29:11 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=115</guid>
		<description><![CDATA[There are many tools around that will help cache your website to increase speed and performance, such as eAccelerator and APC. However these usually require installation on your web server, thus rendering them useless for people who use shared hosting and don&#8217;t have access to the server. Using some simple PHP code we can quite [...]]]></description>
			<content:encoded><![CDATA[<p>There are many tools around that will help cache your website to increase speed and performance, such as <a href="http://eaccelerator.net/">eAccelerator</a> and <a href="http://pecl.php.net/package/APC">APC</a>. However these usually require installation on your web server, thus rendering them useless for people who use shared hosting and don&#8217;t have access to the server.</p>
<p>Using some simple PHP code we can quite effectively cache a webpage, useful for sites that are database driven and have a large amount of queries or high volumes of traffic.</p>
<p>First we need to setup the folder where the cached files are stored, making sure it has read/write permissions (CHMOD to 0777 &#8211; see your FTP client documentation on how to do this).</p>
<p>Next create a file called cache.php which contains the following code:</p>
<div class="php geshi no php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Number of seconds a page should remain cached for</span><br />
<span style="color: #000088;">$cache_expires</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Path to the cache folder</span><br />
<span style="color: #000088;">$cache_folder</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/home/usr/www/cache/&quot;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Checks whether the page has been cached or not</span><br />
<span style="color: #000000; font-weight: bold;">function</span> is_cached<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cache_folder</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cache_expires</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cache_folder</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$cachefile_created</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #339933;">@</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$cache_expires</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$cachefile_created</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p><span style="color: #666666; font-style: italic;">// Reads from a cached file</span><br />
<span style="color: #000000; font-weight: bold;">function</span> read_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cache_folder</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cache_folder</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #b1b100;">return</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p><span style="color: #666666; font-style: italic;">// Writes to a cached file</span><br />
<span style="color: #000000; font-weight: bold;">function</span> write_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$out</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cache_folder</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cache_folder</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#39;w&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$out</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p><span style="color: #666666; font-style: italic;">// Let&#39;s begin, first work out the cached filename</span><br />
<span style="color: #000088;">$cache_file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;REQUEST_URI&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Check if it has already been cached and not expired</span><br />
<span style="color: #666666; font-style: italic;">// If true then we output the cached file contents and finish</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_cached<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #b1b100;">echo</span> read_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p><span style="color: #666666; font-style: italic;">// Ok so the page needs to be cached</span><br />
<span style="color: #666666; font-style: italic;">// Turn on output buffering</span><br />
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
<p>Now in your page you would include cache.php on the <strong>first line</strong> before you do anything else. This is because if the page is cached we don&#8217;t want it to do anything else other than output the cache to the page. If you are still including other files or connecting to databases before checking for the cache you are putting additional load on the server, making this exercise pointless.</p>
<p>Finally create a file called cache_footer.php which contains the following code:</p>
<div class="php geshi no php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Grab the uncached page contents</span><br />
<span style="color: #000088;">$cache_contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Save it to the cache for next time</span><br />
write_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cache_contents</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div>
<p>You would include this file on the <strong>last line</strong> of your page, which saves the page in the cache if required.</p>
<p>Putting it altogether a typical page would look like this:</p>
<div class="php geshi no php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Load the cache process</span><br />
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cache.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Connect to database</span><br />
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;config.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db_username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db_password</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_name</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>Articles<span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Some query</span><br />
<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM articles ORDER BY id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&#39;&lt;li&gt;&lt;a href=&quot;view_article.php?id=&#39;</span><span style="color: #339933;">.</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;id&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&#39;&quot;&gt;&#39;</span><span style="color: #339933;">.</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;title&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&#39;&lt;/a&gt;&lt;/li&gt;&#39;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Save the cache</span><br />
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cache_footer.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/01/15/simple-php-caching/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GoLinks &#8211; PHP/MySQL Links Directory Script</title>
		<link>http://www.xeweb.net/2010/01/14/golinks-php-mysql-links-directory-script/</link>
		<comments>http://www.xeweb.net/2010/01/14/golinks-php-mysql-links-directory-script/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 13:07:47 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Company]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=111</guid>
		<description><![CDATA[Here at XEWeb we are cracking open a bottle of champagne as we announce the new version of GoLinks. GoLinks is a simple yet powerful and efficient links directory script with many features including unlimited categories, link submission, search engine friendly URL&#8217;s, multiple themes and language support with completely customizable templates. Take a look at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.golinks-script.com/"><img src="http://www.xeweb.net/wp-content/uploads/golinkslogo.jpg" alt="GoLinks" width="150" height="21" class="alignleft size-full wp-image-113" /></a>Here at XEWeb we are cracking open a bottle of champagne as we announce the new version of <a href="http://www.golinks-script.com/">GoLinks</a>.</p>
<p>GoLinks is a simple yet powerful and efficient links directory script with many features including unlimited categories, link submission, search engine friendly URL&#8217;s, multiple themes and language support with completely customizable templates.</p>
<p>Take a look at <a href="http://www.golinks-script.com">http://www.golinks-script.com</a> to download, order and view a demo online.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/01/14/golinks-php-mysql-links-directory-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple and lightweight Javascript calendar</title>
		<link>http://www.xeweb.net/2010/01/07/a-simple-and-lightweight-javascript-calendar/</link>
		<comments>http://www.xeweb.net/2010/01/07/a-simple-and-lightweight-javascript-calendar/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 12:35:30 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=110</guid>
		<description><![CDATA[This Javascript code will display a calendar in a table, useful for date picking&#8230; // these are labels for the days of the week cal_days_labels = &#91;&#39;Sun&#39;, &#39;Mon&#39;, &#39;Tue&#39;, &#39;Wed&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;&#93;; // these are human-readable month name labels, in order cal_months_labels = &#91;&#39;January&#39;, &#39;February&#39;, &#39;March&#39;, &#39;April&#39;, &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This Javascript code will display a calendar in a table, useful for date picking&#8230;</p>
<div class="javascript geshi no javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// these are labels for the days of the week</span><br />
cal_days_labels <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&#39;Sun&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;Mon&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;Tue&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;Wed&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;Thu&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;Fri&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;Sat&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #006600; font-style: italic;">// these are human-readable month name labels, in order</span><br />
cal_months_labels <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&#39;January&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;February&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;March&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;April&#39;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #3366CC;">&#39;May&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;June&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;July&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;August&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;September&#39;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #3366CC;">&#39;October&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;November&#39;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&#39;December&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #006600; font-style: italic;">// these are the days of the week for each month, in order</span><br />
cal_days_in_month <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">31</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">28</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">31</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">31</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">31</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">31</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">31</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">31</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #006600; font-style: italic;">// this is the current date</span><br />
<span style="color: #003366; font-weight: bold;">var</span> cal_current_date <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #003366; font-weight: bold;">function</span> Calendar<span style="color: #009900;">&#40;</span>month<span style="color: #339933;">,</span> year<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>month<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> month <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> cal_current_date.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> month<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>year<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> year <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> cal_current_date.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> year<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p>Calendar.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">generateHTML</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></p>
<p>&nbsp; <span style="color: #006600; font-style: italic;">// get first day of month</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> firstDay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> startingDay <span style="color: #339933;">=</span> firstDay.<span style="color: #660066;">getDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #006600; font-style: italic;">// find number of days in month</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> monthLength <span style="color: #339933;">=</span> cal_days_in_month<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #006600; font-style: italic;">// compensate for leap year</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// February only!</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">100</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">400</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; monthLength <span style="color: #339933;">=</span> <span style="color: #CC0000;">29</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></p>
<p>&nbsp; <span style="color: #006600; font-style: italic;">// get todays date</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> cal_today_date <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; checkDay <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>cal_today_date.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">&amp;&amp;</span> cal_today_date.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #006600; font-style: italic;">// do the header</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> monthName <span style="color: #339933;">=</span> cal_months_labels<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span><span style="color: #009900;">&#93;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> html <span style="color: #339933;">=</span> <span style="color: #3366CC;">&#39;&lt;table class=&quot;calendar-table&quot; cellpadding=&quot;4&quot; cellspacing=&quot;0&quot;&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;tr&gt;&lt;th&gt;&lt;a href=&quot;javascript:cal.prevMonth()&quot;&gt;&amp;#171;&lt;/a&gt;&lt;/th&gt;&lt;th colspan=&quot;5&quot;&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; html <span style="color: #339933;">+=</span> &nbsp;monthName <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&amp;nbsp;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span><span style="color: #339933;">;</span><br />
&nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;/th&gt;&lt;th&gt;&lt;a href=&quot;javascript:cal.nextMonth()&quot;&gt;&amp;#187;&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;tr class=&quot;calendar-header&quot;&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;td class=&quot;calendar-header-day&quot;&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; html <span style="color: #339933;">+=</span> cal_days_labels<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;/td&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;/tr&gt;&lt;tr&gt;&#39;</span><span style="color: #339933;">;</span></p>
<p>&nbsp; <span style="color: #006600; font-style: italic;">// fill in the days</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> day <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #006600; font-style: italic;">// this loop is for is weeks (rows)</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">9</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// this loop is for weekdays (cells)</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;td class=&quot;calendar-day&quot;&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>day <span style="color: #339933;">&lt;=</span> monthLength <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> j <span style="color: #339933;">&gt;=</span> startingDay<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ts <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">generateTimestamp</span><span style="color: #009900;">&#40;</span>day<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>checkDay <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">&amp;&amp;</span> day <span style="color: #339933;">==</span> cal_today_date.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;a class=&quot;today&quot; href=&quot;javascript:void(0)&quot;&gt;&#39;</span> <span style="color: #339933;">+</span> day <span style="color: #339933;">+</span> <span style="color: #3366CC;">&#39;&lt;/a&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;a href=&quot;javascript:void(0)&quot;&gt;&#39;</span> <span style="color: #339933;">+</span> day <span style="color: #339933;">+</span> <span style="color: #3366CC;">&#39;&lt;/a&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; day<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;/td&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// stop making rows if we&#39;ve run out of days</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>day <span style="color: #339933;">&gt;</span> monthLength<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;/tr&gt;&lt;tr&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&#39;&lt;/tr&gt;&lt;/table&gt;&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&#39;calendar-holder&#39;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> html<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p>Calendar.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">generateTimestamp</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>day<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; month <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&#39;&quot;</span> <span style="color: #339933;">+</span> day <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&#39;,&#39;&quot;</span> <span style="color: #339933;">+</span> month <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&#39;,&#39;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&#39;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p>Calendar.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">prevMonth</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">generateHTML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p>Calendar.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">nextMonth</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">11</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">year</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">month</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">generateHTML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div>
<p>To display the calendar for example&#8230;</p>
<div class="html4strict geshi no html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span><br />
<span style="color: #00bbdd;"> &nbsp; &nbsp;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> xml:<span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;en&quot;</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;en&quot;</span> <span style="color: #000066;">dir</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ltr&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Select date<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css/calendar.css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;scripts/calendar.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calendar-holder&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
// <span style="color: #009900;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span><br />
<span style="color: #009900;"> &nbsp;var cal <span style="color: #66cc66;">=</span> new Calendar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span><br />
<span style="color: #009900;"> &nbsp;cal.generateHTML<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span><br />
<span style="color: #009900;"><span style="color: #66cc66;">//</span> <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/01/07/a-simple-and-lightweight-javascript-calendar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert plain text to clickable links in PHP</title>
		<link>http://www.xeweb.net/2010/01/05/convert-plain-text-to-clickable-links-in-php/</link>
		<comments>http://www.xeweb.net/2010/01/05/convert-plain-text-to-clickable-links-in-php/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 10:53:15 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=109</guid>
		<description><![CDATA[A useful function if you want to convert a link in plain text into a clickable link&#8230; function clickable_links&#40;$text&#41; &#123; &#160; $text = eregi_replace&#40;&#39;(((f&#124;ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&#38;//=]+)&#39;, &#39;&#60;a target=&#34;_blank&#34; href=&#34;\1&#34;&#62;\1&#60;/a&#62;&#39;, $text&#41;; &#160; $text = eregi_replace&#40;&#39;([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&#38;//=]+)&#39;, &#39;\1&#60;a target=&#34;_blank&#34; href=&#34;http://\2&#34;&#62;\2&#60;/a&#62;&#39;, $text&#41;; &#160; return $text; &#125;]]></description>
			<content:encoded><![CDATA[<p>A useful function if you want to convert a link in plain text into a clickable link&#8230;</p>
<div class="php geshi no php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> clickable_links<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">eregi_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&amp;//=]+)&#39;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#39;&lt;a target=&quot;_blank&quot; href=&quot;\1&quot;&gt;\1&lt;/a&gt;&#39;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">eregi_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&amp;//=]+)&#39;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#39;\1&lt;a target=&quot;_blank&quot; href=&quot;http://\2&quot;&gt;\2&lt;/a&gt;&#39;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/01/05/convert-plain-text-to-clickable-links-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to setup one time download of your files securely</title>
		<link>http://www.xeweb.net/2010/01/03/how-to-setup-one-time-download-of-your-files-securely/</link>
		<comments>http://www.xeweb.net/2010/01/03/how-to-setup-one-time-download-of-your-files-securely/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 13:11:00 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=102</guid>
		<description><![CDATA[If you are selling a digital product and want to offer it for download but are concerned that people will share the URL to the file, you could use a solution like ClickBank. However the advantage of setting up one time downloads from your server instead is that you have more control over what you [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.xeweb.net/wp-content/uploads/file-download-150x150.gif" alt="How to setup one time download of your files securely" width="150" height="150" class="alignleft size-thumbnail wp-image-105" />If you are selling a digital product and want to offer it for download but are concerned that people will share the URL to the file, you could use a solution like <a href="http://www.clickbank.com">ClickBank</a>. However the advantage of setting up one time downloads from your server instead is that you have more control over what you are selling and you don&#8217;t have to pay any fee&#8217;s.</p>
<p>Let us assume that you have setup and integrated a payment solution (such as PayPal using the IPN, post coming soon on this) and you have a database setup that holds the payment information.</p>
<div class="mysql geshi no mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`transactions`</span> <span style="color: #FF00FF;">&#40;</span><br />
<span style="color: #008000;">`id`</span> <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">5</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #000033;">,</span><br />
<span style="color: #008000;">`transaction<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">50</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span><br />
<span style="color: #008000;">`file<span style="color: #008080; font-weight: bold;">_</span>downloaded`</span> <span style="color: #999900; font-weight: bold;">TINYINT</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">1</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><br />
<span style="color: #FF00FF;">&#41;</span> <span style="color: #000033;">;</span></div>
<p>Now we will create download.php which will be the link sent to the user after they have paid to download your files.</p>
<p>To keep it secure you would include the transaction ID (which would be unique to each payment) as part of the query string, so the link would be:</p>
<p>http://www.site.com/download.php?transaction_id=XX</p>
<p>Now you do need the files to be uploaded somewhere on your web server, however the location will never be revealed. The best way is to put them in a folder outside of the web root so that they cant be accessed via HTTP. However if this is not possible then put them in a folder name that cannot be guessed (use a random password generator if you don&#8217;t have any ideas).</p>
<div class="php geshi no php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Path to the files to be downloaded</span><br />
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&#39;/home/usr/files/blah.zip&#39;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Transaction ID</span><br />
<span style="color: #000088;">$transaction_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;transaction_id&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Connect to database</span><br />
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;localhost&#39;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#39;user&#39;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#39;pass&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;dbname&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Lookup the transaction ID in the database</span><br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM transactions WHERE transaction_id=&#39;<span style="color: #009933; font-weight: bold;">%s</span>&#39;&quot;</span><span style="color: #339933;">,</span><br />
<span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$transaction_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Valid transaction ID?</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Invalid transaction ID!&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p><span style="color: #666666; font-style: italic;">// File already been downloaded?</span><br />
<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;file_downloaded&#39;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;File has already been downloaded, please contact us if you have any problems&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></p>
<p><span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span></p>
<p>&nbsp; <span style="color: #666666; font-style: italic;">// It&#39;s a valid transaction, update the database so that we know the file has been downloaded for next time</span><br />
&nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE transactions SET file_downloaded = 1 WHERE transaction_id=&#39;<span style="color: #009933; font-weight: bold;">%s</span>&#39;&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$transaction_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p>&nbsp; <span style="color: #666666; font-style: italic;">// Now force the file to be downloaded</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Content-Description: File Transfer&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Content-Type: application/octet-stream&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Content-Disposition: attachment; filename=&#39;</span><span style="color: #339933;">.</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Content-Transfer-Encoding: binary&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Expires: 0&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Cache-Control: must-revalidate, post-check=0, pre-check=0&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Pragma: public&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;Content-Length: &#39;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">ob_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/01/03/how-to-setup-one-time-download-of-your-files-securely/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using reCAPTCHA to stop spam in PHP</title>
		<link>http://www.xeweb.net/2010/01/01/using-recaptcha-to-stop-spam-in-php/</link>
		<comments>http://www.xeweb.net/2010/01/01/using-recaptcha-to-stop-spam-in-php/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 13:11:57 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.xeweb.net/?p=91</guid>
		<description><![CDATA[reCAPTCHA helps prevent automated abuse of your site (such as comment spam or bogus registrations) by using a CAPTCHA to ensure that only humans perform certain actions. You may have seen reCAPTCHA in use on many websites (including our forum) as it&#8217;s completely free and comes with an excellent web service which we are going [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.xeweb.net/wp-content/uploads/recaptcha-example-150x125.gif" alt="Using reCAPTCHA to stop spam in PHP" width="150" height="125" class="alignleft size-thumbnail wp-image-93" /><a href="http://recaptcha.net/">reCAPTCHA</a> helps prevent automated abuse of your site (such as comment spam or bogus registrations) by using a CAPTCHA to ensure that only humans perform certain actions.</p>
<p>You may have seen reCAPTCHA in use on many websites (including our <a href="/forum/">forum</a>) as it&#8217;s completely free and comes with an excellent web service which we are going to implement in this article.</p>
<p>The first thing to do is <a href="https://admin.recaptcha.net/accounts/signup/">sign up</a> to reCAPTCHA to receive your public and private key. These keys are used to authorize your account.</p>
<p>Next you need to download the reCAPTCHA library in PHP which can be found on <a href="http://recaptcha.net/plugins/php/">this page</a>. Once you have this you are ready to go.</p>
<p>First we are going to store the public and private key in variables, this would usually go in something like config.php.</p>
<div class="php geshi no php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;recaptchalib.php&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$publickey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&#8230;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$privatekey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&#8230;&quot;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// Rest of your config goes here&#8230;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div>
<p>Now on the page you want to display the CAPTCHA (e.g. register.php) you would include this at the top:</p>
<div class="php geshi no php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Include the config file</span><br />
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#39;config.php&#39;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p><span style="color: #666666; font-style: italic;">// If the form has been submitted</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></p>
<p>&nbsp; <span style="color: #666666; font-style: italic;">// Send the CAPTCHA results to reCAPTCHA</span><br />
&nbsp; <span style="color: #000088;">$resp</span> <span style="color: #339933;">=</span> recaptcha_check_answer <span style="color: #009900;">&#40;</span><span style="color: #000088;">$privatekey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;REMOTE_ADDR&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;recaptcha_challenge_field&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#39;recaptcha_response_field&#39;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></p>
<p>&nbsp; <span style="color: #666666; font-style: italic;">// Incorrect CAPTCHA?</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$resp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_valid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&#39;The reCAPTCHA was not entered correctly!&#39;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></p>
<p>&nbsp; <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Otherwise continue with further validation etc</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div>
<p>Now on the same page we display the actual CAPTCHA which is generated by the library so we don&#8217;t have to worry about any HTML or Javascript.</p>
<div class="html4strict geshi no html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span><br />
<span style="color: #808080; font-style: italic;">&lt;!&#8211; Form fields would go here &#8211;&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;?php echo recaptcha_get_html<span style="color: #66cc66;">&#40;</span>$publickey<span style="color: #66cc66;">&#41;</span>; ?&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Complete Sign Up&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.xeweb.net/2010/01/01/using-recaptcha-to-stop-spam-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
