<?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>Tortoise IT &#187; Teaching</title>
	<atom:link href="http://www.sean-barton.co.uk/category/teaching/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sean-barton.co.uk</link>
	<description>by Sean Barton, a freelance PHP website developer in Crewe, Cheshire</description>
	<lastBuildDate>Tue, 31 Jan 2012 17:34:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PHP source code protection &#8211; the basics</title>
		<link>http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/</link>
		<comments>http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 18:33:03 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=540</guid>
		<description><![CDATA[If you have ever sold or considered selling your code/application you would most likely have thought, if only briefly, about stopping people from buying a copy of your code then passing it to their ten friends (disclaimer: not all people have ten friends! some have more (or less!)) for free. &#8216;Why not add a product key?&#8217; you ask! Well yes a product key would do the job and avert the efforts of a portion of these people but obviously when using an interpreted/scripted language such as PHP they will be able to open up your source code, remove any license &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-544" title="Padlock" src="http://www.sean-barton.co.uk/wp-content/uploads/2011/04/Padlock-300x284.jpg" alt="" width="180" height="170" />If you have ever sold or considered selling your code/application you would most likely have thought, if only briefly, about stopping people from buying a copy of your code then passing it to their ten friends (disclaimer: not all people have ten friends! some have more (or less!)) for free.</p>
<p><strong>&#8216;Why not add a product key?&#8217; you ask!</strong></p>
<p>Well yes a product key would do the job and avert the efforts of a portion of these people but obviously when using an interpreted/scripted language such as PHP they will be able to open up your source code, remove any license  checking code and then pass the &#8216;cracked&#8217; version around as before. Generally it&#8217;s not hard to find this sort of code&#8230; simply look for any filenames which hint at &#8216;licensing&#8217; or &#8216;auth&#8217;, open them up (usually very small files) and put a &#8216;return true;&#8217; at the start of the key checking method.  As I said this method stops a large portion of people from passing it around so it&#8217;s still worth doing.</p>
<p><strong>What about a &#8216;call home&#8217; script?</strong></p>
<p>Same story here I&#8217;m afraid but more convenient for the seller (and you can get some lovely stats on the people using your code). A Call Home script is simply a piece of code that runs on the client site (per page load? per admin page load? every day on a CRON job?) and in effect sends a request back to a central server run by the code seller (you?) to simply authenticate sites. If, for example, example.com buys a script from <em>my_premiumscripts.com</em> then installs it on their server&#8230; Every so often the example.com server will call the <em>my_premiumscripts.com</em> server and have the following conversation:</p>
<p><em>example.com (e)</em>: Dude?<br />
<em>my_premiumscripts.com (m)</em>: Dude?<br />
<em>e</em>: So&#8230; I&#8217;m just checking in with you, everything ok?<br />
<em>m</em>: Ah great stuff, yes I see you purchased a copy of my code. Feel free to carry on using it.<br />
<em>e</em>: Brilliant!<br />
<em>m</em>: Indeed. don&#8217;t forget to check in with me tomorrow though.<br />
<em>e</em>: Ok bye!</p>
<p>Or they could say this:</p>
<p><em>example_dotcomsmate.com (e)</em>: Dude?<br />
<em>my_premiumscripts.com</em><em> (m)</em>: Dude?<br />
<em>e</em>: So&#8230; I&#8217;m just checking in with you, everything ok?<br />
<em>m</em>: Who are you again?<br />
<em>e</em>: I&#8217;m a new site you don&#8217;t know about. I got your script from a friend (torrent? friend? unauthorised reseller?)<br />
<em>m</em>: Oh ok, that&#8217;s fine with me but you have to send me some money first before you can use the software.<br />
<em>e</em>: What? Hey I just want to have a look at it for a few days (years)<br />
m: Nope sorry, I am going to deactivate the software on your site now. Bye!<br />
e: Oh ok, bye!</p>
<p>Ok I jazzed up the conversation a bit but you get the idea. Call home scripts work really well from a protection point of view but have one really major drawback&#8230; they require you, as the seller, to have a 100% uptime server and it requires either the client server or the clients users to each initiate a request to that server. This means that both your server is going to get a lot of, what can only be described as, logging traffic (useless to everyone really) and the clients (servers or client machines) are going to get a worse (slower) user experience because of it. That and if you ever decide to move server or domain for the script then there is a lot of admin to do.</p>
<p>Either way there is the potential for you lose out on potential lovely cash. What we need is to be able to use the product key method with a way of stopping people from getting at the source code. There are a few ways to do this, some more awkward than others (both for the purchaser and the developer). The two worth mentioning are:</p>
<p><strong>Code Encryption</strong></p>
<p>This is the daddy of code protection. If your code is protected by an encryption algorithm then people are unable to look at the source code no matter how resourceful. The real downside of this is that you have to force your users to install additional server software before your code will run on their server. No simple FTP it up and start using it type system; this method is likely to involve your server host and a support ticket or two. An example of this would be any system that uses Ioncube Loader which, I understand to be, the same sort of thing.</p>
<p><strong>Code Obfuscation</strong></p>
<p>This is the lighter and more manageable version of the above. Whenever you look at an obfuscated file it will appear jibberish to the reader. PHP can interpret it because it doesn&#8217;t care whether a variable or function/method has a name which is human readable or not. Obfuscation works by removing all whitespace, renaming functions and variables and swapping out ascii text for a different characterset/encoding which is not immediately obvious to a novice that it&#8217;s text. Often these scripts make use of nested loops, dummy methods and evaluated code (code as a string which has then had the eval() function passed over it. Base64 encoding is popular but very easy to spot and decode to it&#8217;s use is on the decline. No additional software is required to run obfuscated code, it&#8217;s just a pain when there is an error in the code and the developer, for example, is on holiday for the next month! The downside of this for the developer is that it can be decoded and reverted to something resembling it&#8217;s original form (minus original function and variable names) by simply working backwards. Well&#8230; it&#8217;s not simple at all but is doable! Many virus script writers use this method of hiding a scripts intention. I have had to decode a few myself and it&#8217;s not fun.</p>
<p><strong>Recommendations</strong></p>
<p>My only recommendation is going to be to use neither and just go with a simple product key. Yes you are going to get taken for a ride by some people who want to redistribute it amongst their friends but think about it&#8230; they can&#8217;t get any updates from you, no support and if their source of the code disappears then they might even come and buy from you in the first place.</p>
<p>The key is to constantly be working on your scripts/applications. Don&#8217;t settle on a single version for too long, encourage a good community around the work and most importantly don&#8217;t rip people off in the first place&#8230; if the price is reasonable then people will happily pay it. A cheaper price is also a nice reason to offer sightly less involved support. It&#8217;s also a possible avenue of further income, premium support etc..</p>
<p>The real issue with any form of code protection is that updates and critical fixes won&#8217;t work without the original developer putting a new package together and, often, the entire fileset being replaced. If something goes wrong and the developer is not available then the job can not be outsourced which causes more issues. This is why I would always recommend you stand behind a well written Terms and Conditions document which must be agreed before the software can be used. Generally a block in the code is a challenge to be overcome, a legal document that requires signing and makes you liable is not!</p>
<p>Thanks for reading!</p>
<p><em>nb: example.com, example_dotcomsmate.com and </em><em>my_premiumscripts.com</em><em> are fabricated and although they might exist have no relation to the content in this article.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2011/04/php-source-code-protection-the-basics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Live Countdown Timer using Javascript</title>
		<link>http://www.sean-barton.co.uk/2009/10/live-countdown-timer-using-javascript/</link>
		<comments>http://www.sean-barton.co.uk/2009/10/live-countdown-timer-using-javascript/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 10:52:40 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Teaching]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[timer]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=350</guid>
		<description><![CDATA[Been done? Yes of course it has! However you don&#8217;t learn anything unless you get stuck in and have a go yourself and that is exactly what I did during an empty half hour period I had the other day (slow lecture). Whilst at university I am doing a lot of timed tasks (ten minutes etc.. as opposed to days) and the timers used are always a mobile phone timer or horrible Powerpoint countdown presentation. I wanted to write something which is simple to build on to create a JS version to ultimately integrate into online resources and lessons (Eg: &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2009/10/live-countdown-timer-using-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Been done? Yes of course it has! However you don&#8217;t learn anything unless you get stuck in and have a go yourself and that is exactly what I did during an empty half hour period I had the other day (slow lecture). Whilst at university I am doing a lot of timed tasks (ten minutes etc.. as opposed to days) and the timers used are always a mobile phone timer or horrible Powerpoint countdown presentation. I wanted to write something which is simple to build on to create a JS version to ultimately integrate into online resources and lessons (Eg: this task will take you ten minutes. Click here to turn on the timer&#8230;).</p>
<p>The  code at the bottom of this post is the raw HTML file I wrote. I obviously made it into a WordPress plugin as well. see below example.</p>
<p><strong>Example</strong></p>
<p>Yes, it&#8217;s basic but it works well for demonstrative purposes.</p>
<div id="countdown_body_wrapper">
                <form id="countdown_form" onsubmit="return do_countdown();">
                    Countdown from: <input style="width: 50px;" id="value" />
                    <select id="countdown_unit">
                        <option value="1">Seconds</option>
                        <option value="60">Minutes</option>
                        <option value="3600">Hours</option>
                    </select>
                    <input type="submit" value="Go" />
                </form>
                <div id="countdown_div"></div>
            </div>
<p><strong>Usage</strong></p>
<p>write sb_countdown in square brackets in a post or page and you will get the above example. If you want to edit the text or style it then just open the plugin file and right near the top is a few defines to get you going. I didn&#8217;t spend a lot of time on it so didn&#8217;t create an admin page. I may well do in the future though.</p>
<p><strong>The Download</strong></p>
<a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=15" title="Version 1 downloaded 541 times" >SB JS Countdown Timer (1.42 kB)</a>
<p><strong>Raw HTML Version</strong></p>
<pre>&lt;html&gt;
 &lt;head&gt;
 &lt;title&gt;Countdown Timer&lt;/title&gt;

 &lt;style&gt;
 body {
 font-family: tahoma;
 }

 #countdown_div {
 font-weight: bold;
 font-size: 56px;
 }

 #body_wrapper {
 padding: 10px;
 margin: 20px;
 }
 &lt;/style&gt;

 &lt;script&gt;
 function do_countdown() {
 var start_num = document.getElementById("value").value;
 var unit_var = document.getElementById("countdown_unit").value;

 start_num = start_num * parseInt(unit_var);

 var countdown_output = document.getElementById('countdown_div');

 if (start_num &gt; 0) {
 countdown_output.innerHTML = format_as_time(start_num);
 var t=setTimeout("update_clock(\"countdown_div\", "+start_num+")", 1000);
 }

 return false;
 }

 function update_clock(countdown_div, new_value) {
 var countdown_output = document.getElementById(countdown_div);
 var new_value = new_value - 1;

 if (new_value &gt; 0) {
 new_formatted_value = format_as_time(new_value);
 countdown_output.innerHTML = new_formatted_value;

 var t=setTimeout("update_clock(\"countdown_div\", "+new_value+")", 1000);
 } else {
 countdown_output.innerHTML = "And... Stop!";
 }
 }

 function format_as_time(seconds) {
 var minutes = parseInt(seconds/60);
 var seconds = seconds - (minutes*60);

 if (minutes &lt; 10) {
 minutes = "0"+minutes;
 }

 if (seconds &lt; 10) {
 seconds = "0"+seconds;
 }

 var return_var = minutes+':'+seconds;

 return return_var;
 }
 &lt;/script&gt;
 &lt;/head&gt;

 &lt;body&gt;
 &lt;div id="body_wrapper"&gt;
 &lt;form id="countdown_form" onsubmit="return do_countdown();"&gt;
 Countdown from: &lt;input style="width: 50px;" id="value" /&gt;
 &lt;select id="countdown_unit"&gt;
 &lt;option value="1"&gt;Seconds&lt;/option&gt;
 &lt;option value="60"&gt;Minutes&lt;/option&gt;
 &lt;option value="3600"&gt;Hours&lt;/option&gt;
 &lt;/select&gt;
 &lt;input type="submit" value="Go" /&gt;
 &lt;/form&gt;
 &lt;div id="countdown_div"&gt;&amp;nbsp;&lt;/div&gt;
 &lt;/div&gt;
 &lt;/body&gt;

&lt;/html&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/10/live-countdown-timer-using-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Learning Event Generator</title>
		<link>http://www.sean-barton.co.uk/2009/09/learning-event-generator/</link>
		<comments>http://www.sean-barton.co.uk/2009/09/learning-event-generator/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 18:32:05 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[lesson planning]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=343</guid>
		<description><![CDATA[The learning event generator is something which I was shown on the first day of my PGCE. It was demonstrated and was intriguing to say the least! It would be an interesting way to allow the children we teach to decide their own activities. I have been in a coding mood today so thought that I would bash together a tiny little PHP script to emulate the same thing. Yes it&#8217;s basic but works from two text files which are defined in the first few lines of the file itself. It&#8217;s not the most elegant bit of code I have &#8230; <a class="continue_reading" href="http://www.sean-barton.co.uk/2009/09/learning-event-generator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The learning event generator is something which I was shown on the first day of my PGCE. It was demonstrated and was intriguing to say the least! It would be an interesting way to allow the children we teach to decide their own activities.</p>
<p>I have been in a coding mood today so thought that I would bash together a tiny little PHP script to emulate the same thing. Yes it&#8217;s basic but works from two text files which are defined in the first few lines of the file itself. It&#8217;s not the most elegant bit of code I have ever written but if you know anything about PHP or have a web server then why not have a fiddle and see what you can make it do?</p>
<p>Consider this&#8230; it doesn&#8217;t have to be learning events. Why not use it as a kind of &#8216;What shall we do tomorrow?&#8217; kind of thing. eg: &#8216;Do a 5 mile run with a friend dressed as a horse&#8217; or &#8216;Do go out and get a bit merry&#8217;.</p>
<p><strong>The Code</strong></p>
<pre>&lt;?php

$cwd = getcwd();
$outcome_source = $cwd . '/' . 'activities.txt';
$method_source = $cwd . '/' . 'methods.txt';

$outcomes = file($outcome_source);
$methods = file($method_source);

$outcome = trim($outcomes[array_rand($outcomes)]);
$method = trim($methods[array_rand($methods)]);

echo 'Do ' . $outcome . ' as a ' . $method . '.';

?&gt;</pre>
<p><strong>The Download</strong></p>
<p>The file is available as a download here: <a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=14" title="Version 1 downloaded 399 times" >Learning Event Generator (1.23 kB)</a></p>
<p><strong>References</strong></p>
<p>The original idea is available on the following <a title="Learning Event Generator Homepage" href="http://www.newtools.org/showtxt.php?docid=724" target="_blank">website</a> and is credited to John Davitt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/09/learning-event-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 8/30 queries in 0.064 seconds using disk
Object Caching 427/451 objects using disk

Served from: www.sean-barton.co.uk @ 2012-02-08 23:03:01 -->
