<?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>3cc Internet</title>
	<atom:link href="http://www.3cc.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3cc.org</link>
	<description>Simplifying sites</description>
	<lastBuildDate>Sat, 31 Dec 2011 15:51:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>New Flash Game &#8211; Flightpath</title>
		<link>http://www.3cc.org/2011/05/new-flash-game-flightpath/</link>
		<comments>http://www.3cc.org/2011/05/new-flash-game-flightpath/#comments</comments>
		<pubDate>Sun, 08 May 2011 15:05:43 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Project Updates]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash game]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[solidgamers]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=320</guid>
		<description><![CDATA[We published a new game earlier this week &#8211; Flightpath. Play Flightpath at SolidGamers.com You&#8217;ve got a million mile quota to fly around the world and collect all the packages. It&#8217;s high scores enabled so you can challenge friends &#38; beat their mileage.]]></description>
			<content:encoded><![CDATA[<p>We published a new game earlier this week &#8211; Flightpath. <a title="Free Online Games at SolidGamers.com" href="http://www.solidgamers.com/play/4689/flightpath.html">Play Flightpath at SolidGamers.com</a></p>
<p>You&#8217;ve got a million mile quota to fly around the world and collect all the packages. It&#8217;s high scores enabled so you can challenge friends &amp; beat their mileage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2011/05/new-flash-game-flightpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook Like Buttons, &amp;fb_xd_fragment=, Blank pages and SEO</title>
		<link>http://www.3cc.org/2011/04/facebook-like-buttons-fb_xd_fraglment-blank-pages-and-seo/</link>
		<comments>http://www.3cc.org/2011/04/facebook-like-buttons-fb_xd_fraglment-blank-pages-and-seo/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 17:39:52 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=307</guid>
		<description><![CDATA[This is a software development problem that&#8217;s been around for months now and yet still bugs thousands of users. Any of your pages with facebook widgets on can result in URL&#8217;s like www.example.com/page.php?fb_xd_fragment= This has several implications. Firstly &#8211; it can cause blank pages through unwanted interactions with div areas on the page. We can [...]]]></description>
			<content:encoded><![CDATA[<p>This is a <a href="http://www.elinext.com/" class="clear_url">software development</a> problem that&#8217;s been around for months now and yet still bugs thousands of users.</p>
<p>Any of your pages with facebook widgets on can result in URL&#8217;s like</p>
<p>www.example.com/page.php?fb_xd_fragment=</p>
<p>This has several implications. Firstly &#8211; it can cause blank pages through unwanted interactions with div areas on the page. We can solve this by adding the following fix just before the &lt;/body&gt; tag. This came from http://forum.developers.facebook.net/viewtopic.php?id=60571&amp;p=1 (temporary solutions)</p>
<pre class="brush: js">&lt;!-- Correct fb_xd_fragment Bug Start --&gt;
&lt;script&gt;
document.getElementsByTagName('html')[0].style.display='block';
&lt;/script&gt;
&lt;!-- Correct fb_xd_fragment Bug End --&gt;</pre>
<p>The second, more long term issue is that this page will appear in search results alongside the normal page&#8230;resulting in duplicate content. Obviously you could just remove the like button but that&#8217;s not an ideal solution. So you can do a couple of things.</p>
<p>Head to webmastertools (https://www.google.com/webmasters/tools/home?hl=en) and add the fb_xd_fragment= as something that should be ignored on your site.</p>
<div id="attachment_308" class="wp-caption aligncenter" style="width: 610px"><img class="size-large wp-image-308" title="Filtering out fb_xd_fragment in Google Webmaster Tools" src="http://www.3cc.org/wp-content/uploads/2011/04/google_webmaster_tools-600x412.png" alt="Filtering out fb_xd_fragment in Google Webmaster Tools" width="600" height="412" /><p class="wp-caption-text">Filtering out fb_xd_fragment in Google Webmaster Tools</p></div>
<p>Another option is to use .htaccess and 301 redirects to clip out the &amp;fb_xd_fragment=, which is a pain but very easily do-able and removes the requirement to put the display fix on every page. So try this (modified per your site) in your .htaccess.</p>
<p>RewriteCond %{QUERY_STRING} fb_xd_fragment=<br />
RewriteRule ^(.*) http://www.example.com/$1? [R=301]</p>
<p>You could also ignore it and just hope facebook fixes it soon&#8230;yeahh bad choices right?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2011/04/facebook-like-buttons-fb_xd_fraglment-blank-pages-and-seo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Giving away some Google Adwords £50 Vouchers</title>
		<link>http://www.3cc.org/2011/04/giving-away-some-google-adwords-50-vouchers/</link>
		<comments>http://www.3cc.org/2011/04/giving-away-some-google-adwords-50-vouchers/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 20:47:16 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Marketing]]></category>
		<category><![CDATA[google adwords]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=300</guid>
		<description><![CDATA[Giving away three Google Adwords £50 vouchers! Standard terms apply, new accounts only, £50 value drops to £30 on 19/04/2011. UPDATE: All gone, will post some more up when I have more.]]></description>
			<content:encoded><![CDATA[<p>Giving away three Google Adwords £50 vouchers!</p>
<div id="attachment_301" class="wp-caption aligncenter" style="width: 610px"><img class="size-large wp-image-301" title="£50 FREE Adwords Coupon" src="http://www.3cc.org/wp-content/uploads/2011/04/IMAG0305-600x359.jpg" alt="£50 FREE Adwords Coupon" width="600" height="359" /><p class="wp-caption-text">£50 FREE Adwords Coupon</p></div>
<p>Standard terms apply, new accounts only, £50 value drops to £30 on 19/04/2011.</p>
<p><strong>UPDATE: </strong>All gone, will post some more up when I have more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2011/04/giving-away-some-google-adwords-50-vouchers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>3arcade (ArcadeBlocks v2) Released</title>
		<link>http://www.3cc.org/2011/02/3arcade-arcadeblocks-v2-released/</link>
		<comments>http://www.3cc.org/2011/02/3arcade-arcadeblocks-v2-released/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 14:17:53 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[3arcade]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=291</guid>
		<description><![CDATA[We&#8217;ve released an improved version of ArcadeBlocks &#8211; 3arcade! ArcadeBlocks was released about 3 years ago and was popular as a simple, low cost arcade script. It was very basic with regards to features but this allowed it to be slotted into existing sites very easily. 3arcade represents a huge improvement over ArcadeBlocks &#8211; not [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve released an improved version of ArcadeBlocks &#8211; <strong>3arcade</strong>!</p>
<p>ArcadeBlocks was released about 3 years ago and was popular as a simple, low cost arcade script. It was very basic with regards to features but this allowed it to be slotted into existing sites very easily.</p>
<p>3arcade represents a huge improvement over ArcadeBlocks &#8211; not only are security, features and styles improved but the admin panel is much easier to use.</p>
<p>Why not try the demo? Or even better purchase a copy?<br />
<a href="http://www.3cc.org/scripts/3arcade-arcade-script/">http://www.3cc.org/scripts/3arcade-arcade-script/</a></p>
<p>p.s. The original version of the script is now free&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2011/02/3arcade-arcadeblocks-v2-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>phpBB 3 Script Integration &#8211; New Threads and Replies from an External Script</title>
		<link>http://www.3cc.org/2010/09/phpbb-3-script-integration-new-threads-and-replies-from-an-external-script/</link>
		<comments>http://www.3cc.org/2010/09/phpbb-3-script-integration-new-threads-and-replies-from-an-external-script/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 11:21:24 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpbb]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=217</guid>
		<description><![CDATA[This is the third article I&#8217;ve written for pulling functions in phpBB3 for external use. This one allows you to either create new posts in a forum or reply to a thread. This was created for use with a text system, where users could text in comments which would be added to a thread. Article [...]]]></description>
			<content:encoded><![CDATA[<p>This is the third article I&#8217;ve written for pulling functions in phpBB3 for external use. This one allows you to either create new posts in a forum or reply to a thread. This was created for use with a text system, where users could text in comments which would be added to a thread.</p>
<p><a href="http://www.3cc.org/2010/03/integrating-your-existing-site-into-phpbb3/" target="_blank">Article on phpBB3 Integration</a><br />
<a href="http://www.3cc.org/2010/09/phpbb-3-script-integration-sending-private-messages-pms-from-an-external-script/" target="_blank">Article on sending PM&#8217;s</a></p>
<p>I&#8217;ve put everything needed into one file as I don&#8217;t want to go through and break it up. The previous two posts (linked above) used a seperate phpbb.php file with part of the code in but this just includes everything.</p>
<pre class="brush: php">&lt;?php
// All queries --&gt; support@3cc.org
// This is not setup for new thread posting, and has been config'd to not increment post count as this is for a bot.
// Further changes will be needed to clean up code as this is using external functions instead of clear documentation. --dc
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './phpBB3/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user-&gt;session_begin();
$auth-&gt;acl($user-&gt;data);
$user-&gt;setup();

// post send controller
function sendphpbbpost($pmmessage,$userid,$pmsubject) {

include_once('phpBB3/includes/functions_posting.php');
$my_subject = utf8_normalize_nfc(request_var('$pmsubject', '', true));
$message = utf8_normalize_nfc($pmmessage, '', true);
$uid = $bitfield = $options = '';
$allow_bbcode = $allow_smilies = true;
$allow_urls = true;
generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$data = array(
// General Posting Settings
'forum_id'          =&gt; 7,    // The forum ID in which the post will be placed. (int)
'topic_id'          =&gt; 5,    // Post a new topic or in an existing one? Set to 0 to create a new one, if not, specify your topic ID here instead.
'icon_id'           =&gt; false,    // The Icon ID in which the post will be displayed with on the viewforum, set to false for icon_id. (int)

// Defining Post Options
'enable_bbcode' =&gt; false, // Enable BBcode in this post. (bool)
'enable_smilies'    =&gt; true, // Enabe smilies in this post. (bool)
'enable_urls'       =&gt; false, // Enable self-parsing URL links in this post. (bool)
'enable_sig'        =&gt; true, // Enable the signature of the poster to be displayed in the post. (bool)

// Message Body
'message'           =&gt; $message,     // Your text you wish to have submitted. It should pass through generate_text_for_storage() before this. (string)
'message_md5'   =&gt; md5($message),    // The md5 hash of your message

// Values from generate_text_for_storage()
'bbcode_bitfield'   =&gt; $bitfield,    // Value created from the generate_text_for_storage() function.
'bbcode_uid'        =&gt; $uid,     // Value created from the generate_text_for_storage() function.

// Other Options
'post_edit_locked'  =&gt; 0,
'topic_title'       =&gt; $subject, // Subject/Title of the topic. (string). This is needed for new posts but for our purposes isn't.

// Email Notification Settings
'notify_set'        =&gt; false,        // (bool)
'notify'            =&gt; false,        // (bool)
'post_time'         =&gt; 0,        // Set a specific time, use 0 to let submit_post() take care of getting the proper time (int)
'forum_name'        =&gt; '',       // For identifying the name of the forum in a notification email. (string)

// Indexing
'enable_indexing'   =&gt; true,
'force_approved_state' =&gt; true, // Only runs on 6 onwards...check SUCC
);

//Now send that post...
submit_post('reply', '', '', POST_NORMAL, &amp;$poll, &amp;$data, $update_message = true);

}

$user-&gt;data['user_id'] = 2;    // User id of poster.
$auth-&gt;acl($user-&gt;data); // Re-initiate user after recall
$userid = $user-&gt;data['user_id'];
$pmmessage = 'This is a new reply, change this to whatever you want.';
sendphpbbpost($pmmessage,$userid,$pmsubject);

?&gt;</pre>
<p>Looking through the code above you will see several points that need changing. It&#8217;s currently set to &#8216;reply&#8217; (change this to &#8216;post&#8217; for a new post). Change all details to suit really &#8211; it&#8217;s easy to customise.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/09/phpbb-3-script-integration-new-threads-and-replies-from-an-external-script/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>phpBB 3 Script Integration &#8211; Sending Private Messages (PM&#8217;s) From an External Script</title>
		<link>http://www.3cc.org/2010/09/phpbb-3-script-integration-sending-private-messages-pms-from-an-external-script/</link>
		<comments>http://www.3cc.org/2010/09/phpbb-3-script-integration-sending-private-messages-pms-from-an-external-script/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 16:19:52 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpbb]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=214</guid>
		<description><![CDATA[A while back I posted an article about integrating your site to use the phpBB3 user and login system (here). When I wrote that I also used phpBB as a message system for a site; so when a user did something they were sent a private message automatically. This bit of code (use it in [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I posted an article about integrating your site to use the phpBB3 user and login system (<a href="http://www.3cc.org/2010/03/integrating-your-existing-site-into-phpbb3/" target="_blank">here</a>). When I wrote that I also used phpBB as a message system for a site; so when a user did something they were sent a private message automatically.</p>
<p>This bit of code (use it in conjunction with phpbb.php mentioned in the post linked to above) allows you to call a function to send a PM to any user as long as you have their ID.</p>
<pre class="brush: php">&lt;?php
// PM send controller
include_once("phpbb.php");

function sendphpbbpm($pmmessage,$userid,$pmsubject) {
include_once('forum/includes/functions_privmsgs.php');

$message = utf8_normalize_nfc($pmmessage);
$uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage
$allow_bbcode = $allow_smilies = true;
$allow_urls = true;
generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$pm_data = array(
'from_user_id'        =&gt; 2,
'from_user_ip'        =&gt; "127.0.0.1",
'from_username'        =&gt; "admin",
'enable_sig'            =&gt; false,
'enable_bbcode'        =&gt; true,
'enable_smilies'        =&gt; true,
'enable_urls'        =&gt; false,
'icon_id'            =&gt; 0,
'bbcode_bitfield'    =&gt; $bitfield,
'bbcode_uid'         =&gt; $uid,
'message'            =&gt; $message,
'address_list'        =&gt; array('u' =&gt; array($userid =&gt; 'to')),
);

//Now We Have All Data Lets Send The PM!!
submit_pm('post', $pmsubject, $pm_data, false, false);
}

?&gt;</pre>
<p>You&#8217;ll need to modify the code above slightly to fit your needs, for example changing the admin username and user id, and then calling the function but it&#8217;s all pretty simple stuff one you&#8217;ve got all this.</p>
<p>To call the function (send the PM) to a fictional user 11:</p>
<pre class="brush: php">&lt;?php

$pmsubject = 'Please read this PM.';
$pmmessage = 'Thank you for reading this PM!';

$userid = '11';

sendphpbbpm($pmmessage,$userid,$pmsubject);

?&gt;</pre>
<p>Posting threads and replying to threads uses a similar system so I&#8217;ll put up some script for that shortly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/09/phpbb-3-script-integration-sending-private-messages-pms-from-an-external-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmarking and testing your PHP script with microtime</title>
		<link>http://www.3cc.org/2010/09/benchmarking-and-testing-your-php-script-with-microtime/</link>
		<comments>http://www.3cc.org/2010/09/benchmarking-and-testing-your-php-script-with-microtime/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 16:53:44 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[microtime]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=210</guid>
		<description><![CDATA[When you&#8217;re building a new website you often code it &#8216;on-the-fly&#8217;. That&#8217;s to say, strapping in new features here and there until it does exactly what you want &#8211; but leaving a mess that needs to be optimised. One of the best ways of testing your site for scalability (other than getting huge traffic straight [...]]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re building a new website you often code it &#8216;on-the-fly&#8217;. That&#8217;s to say, strapping in new features here and there until it does exactly what you want &#8211; but leaving a mess that needs to be optimised.</p>
<p>One of the best ways of testing your site for scalability (other than getting huge traffic straight away) is to test how long your PHP scripts take to parse. We can do this by comparing the time at the start and end of a script to give us the processing time. The PHP manual shows the following example:</p>
<pre class="brush:php">$time_start = microtime(true);
// Script you want to test here
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Did nothing in $time seconds\n";</pre>
<p>But I prefer this for readability (I put this in a common include so I can test the whole site by simply calling some functions&#8230;see below):</p>
<pre class="brush:php">function starttime() {
$r = explode( ' ', microtime() );
$r = $r[1] + $r[0];
return $r;
}

function endtime($starttime) {
$r = explode( ' ', microtime() );
$r = $r[1] + $r[0];
$r = round($r - $starttime,4);
return '&lt;strong&gt;Execution Time&lt;/strong&gt;: '.$r.' seconds&lt;br /&gt;';
}
</pre>
<p>To use this in a script all we&#8217;d need to do is place this at the start and end, and do a simple calculation. For example (using sudo code):</p>
<pre class="brush:php">$start = starttime();
// Script you want to test here
echo endtime($start);
</pre>
<p>This will help you discover bottlenecks in your script &#8211; there are a load of things you can do to optimise your script; and I find that using functions as above don&#8217;t add extra complication to your script.</p>
<p>For a much more comprehensive article and info on optimisation I would highly reccommend heading here: http://phplens.com/lens/php-book/optimizing-debugging-php.php</p>
<p>He has revealed many of the things people thought sped up PHP execution are simply myths dating back to previous PHP versions, making them pointless. This includes things like echo being faster than print and single quoted vars being faster than double quoted ones.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/09/benchmarking-and-testing-your-php-script-with-microtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Google Maps, Geocoding and PHP to find the distance between UK Postcodes</title>
		<link>http://www.3cc.org/2010/08/using-google-maps-geocoding-and-php-to-find-the-distance-between-uk-postcodes/</link>
		<comments>http://www.3cc.org/2010/08/using-google-maps-geocoding-and-php-to-find-the-distance-between-uk-postcodes/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:57:11 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postcodes]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=140</guid>
		<description><![CDATA[If you&#8217;re looking to make any kind of radius checker, delivery calculator etc, you will need to have some method of calculating this distance. Unfortunately for us in the UK, Royal Mail keep a tight grip on postcode data. As a result, the best low-budget way of finding postcodes is by using the Google Maps [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking to make any kind of radius checker, delivery calculator etc, you will need to have some method of calculating this distance. Unfortunately for us in the UK, Royal Mail keep a tight grip on postcode data.</p>
<p>As a result, the best low-budget way of finding postcodes is by using the Google Maps api &#8211; which in itself isn&#8217;t 100% accurate (but good enough).</p>
<p>So we can use the following code:</p>
<pre class="brush:php">&lt;?php
// Specify Postcodes to Geocode
$postcode1 = 'BH151DA';
$postcode2 = 'BH213AP';

// Geocode Postcodes &amp; Get Co-ordinates 1st Postcode
$pc1 = 'http://maps.google.com/maps/geo?q='.$postcode1.',+UK&amp;output=csv&amp;sensor=false';
$data1 = @file_get_contents($pc1);
$result1 = explode(",", $data1);
$custlat1 = $result1[2];
$custlong1 = $result1[3];

// Geocode Postcodes &amp; Get Co-ordinates 2nd Postcode
$pc2 = 'http://maps.google.com/maps/geo?q='.$postcode2.',+UK&amp;output=csv&amp;sensor=false';
$data2 = @file_get_contents($pc2);
$result2 = explode(",", $data2);
$custlat2 = $result2[2];
$custlong2 = $result2[3];

// Work out the distance!
$pi80 = M_PI / 180;
$custlat1 *= $pi80;
$custlong1 *= $pi80;
$custlat2 *= $pi80;
$custlong2 *= $pi80;

$r = 6372.797; // mean radius of Earth in km
$dlat = $custlat2 - $custlat1;
$dlng = $custlong2 - $custlong1;
$a = sin($dlat / 2) * sin($dlat / 2) + cos($custlat1) * cos($custlat2) * sin($dlng / 2) * sin($dlng / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));

// Distance in KM
$km = round($r * $c, 2);

// Distance in Miles
$miles = round($km * 0.621371192, 2);

echo 'The distance between '.$postcode1.' and '.$postcode2.' is '.$km.'Km ('.$miles.' miles).';

?&gt;
</pre>
<p>You could use $result1[0] and $result2[0] to check codes. If the value is anything other than 200 the postcode is invalid. Also note UK is also searched for to guarantee correct results!</p>
<p>The result is also rounded to make sure we only have 2 decimal places. Make sure your postcodes do not have any spaces in when they go to Google, if you&#8217;re collecting them from a form maybe use:</p>
<pre class="brush:php">function nowhitespace($data) {
return preg_replace('/\s/', '', $data);
}
$postcode1 = nowhitespace($postcode1);</pre>
<p>to remove all spaces before processing, and the following to check it&#8217;s ok after processing:</p>
<pre class="brush:php">if (($result1[0] != 200) || ($result2[0] != 200)) {
echo "&lt;p&gt;Invalid Postcode(s) Entered. Please try again.&lt;/p&gt;";
} else {</pre>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/using-google-maps-geocoding-and-php-to-find-the-distance-between-uk-postcodes/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Vertical Align and Centering Images in Div tags</title>
		<link>http://www.3cc.org/2010/08/vertical-align-and-centering-images-in-div-tags/</link>
		<comments>http://www.3cc.org/2010/08/vertical-align-and-centering-images-in-div-tags/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:26:13 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=197</guid>
		<description><![CDATA[Just thought I&#8217;d share my preferred solution for vertical aligning an image within a Div. You can&#8217;t use &#60;p&#62; tags, text align, vertical align or even image align as this messes up the display? I had this problem with thumbnails or varying sizes which needed to be centered in a div of specific size. Using [...]]]></description>
			<content:encoded><![CDATA[<p>Just thought I&#8217;d share my preferred solution for vertical aligning an image within a Div.</p>
<p>You can&#8217;t use &lt;p&gt; tags, text align, vertical align or even image align as this messes up the display? I had this problem with thumbnails or varying sizes which needed to be centered in a div of specific size.</p>
<p>Using the approach suggested <a href="http://www.w3.org/Style/Examples/007/center#vertical" target="_blank">here</a> and classing it as a table cell wasn&#8217;t great as it messed up the display&#8230;so I just set the image as a background which you can center &amp; put a transparent gif over it to link to. Not ideal but it works!</p>
<pre class="brush:html;">&lt;div style="background-image: url('thumbnail.gif');  background-repeat: no-repeat; background-position: center; width: 100px;  height: 100px"&gt;
&lt;a href="page.php"&gt;
&lt;img src="transparent  gif" width="100" height="100" /&gt;
&lt;/a&gt;
&lt;/div&gt;
</pre>
<p>You could also consider using absolute div tags but that also tends to interfere with surrounding design elements! Other solutions welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/vertical-align-and-centering-images-in-div-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resubmitting forms upon page refresh or reload in PHP</title>
		<link>http://www.3cc.org/2010/08/resubmitting-forms-upon-page-refresh-or-reload-in-php/</link>
		<comments>http://www.3cc.org/2010/08/resubmitting-forms-upon-page-refresh-or-reload-in-php/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 19:03:13 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=191</guid>
		<description><![CDATA[A common problem with forms is the annoying resubmit when the user reloads or refreshes a page. This can result in duplicate database records if not dealt with properly. There are a number of simple solutions to this problem, I&#8217;ll go through a couple below. 1. Use two files (one with the form on and [...]]]></description>
			<content:encoded><![CDATA[<p>A common problem with forms is the annoying resubmit when the user reloads or refreshes a page. This can result in duplicate database records if not dealt with properly.</p>
<p>There are a number of simple solutions to this problem, I&#8217;ll go through a couple below.</p>
<p><strong>1. Use two files (one with the form on and one to process), and redirect back to the first page when the processing is done.</strong></p>
<p>Here&#8217;s some sample code for the form page (form.htm):</p>
<pre class="brush: php">&lt;form name="form1" method="post" action="process.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
</pre>
<p>and here&#8217;s some sample code for the processing page (process.php):</p>
<pre class="brush: php">&lt;?php
if (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
header("Location: form.htm");
}
?&gt;
</pre>
<p>This uses PHP header to redirect the user back to the form page when the form is processed, or if the user directly visits process.php without the form submission. Bear in mind this is only example code and so is not complete or secure.</p>
<p><strong>2. Use two files (one with the form on and to process and one when finished), redirecting to the second page when finished.</strong></p>
<p>Here is some sample code for the process/form page (form.php):</p>
<pre class="brush: php">&lt;?php
if (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
}
header("Location: thanks.htm");
?&gt;
&lt;form name="form1" method="post" action="form.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
</pre>
<p>and here&#8217;s the code for the final page (thanks.htm):</p>
<pre class="brush: php">&lt;p&gt;Thanks for filling out our form!&lt;/p&gt;
</pre>
<p>The user can still refresh the final page as much as they want as the processing was done elsewhere.</p>
<p><strong>3. Use one file, doing all the processing and then displaying a thank you message.</strong></p>
<p>This uses a $_GET to tell the script we&#8217;ve finished and display a message (form.php):</p>
<pre class="brush: php">&lt;?php
if ($_GET['success']) {
echo "Your text was saved successfully!";
} elseif (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
header("Location: form.php?success=1");
}
?&gt;
&lt;form name="form1" method="post" action="form.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
</pre>
<p>I suppose you could change the echo to a die if you didn&#8217;t want to show the form, or add in a final else like this:</p>
<pre class="brush: php">&lt;?php
if ($_GET['success']) {
echo "Your text was saved successfully!";
} elseif (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
header("Location: form.php?success=1");
} else {
?&gt;
&lt;form name="form1" method="post" action="form.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
&lt;?php } ?&gt;
</pre>
<p>so that the form would not be displayed when the Success text was.</p>
<p><strong>4. Involve sessions<br />
</strong></p>
<p>You could also involve sessions in your form by storing the POST variables in a session before processing, eg:</p>
<pre class="brush: php">$_SESSION['postdata'] = $_POST;
</pre>
<p>and clearing the session once the processing had been done, eg:</p>
<pre class="brush: php">unset($_SESSION['postdata'])
</pre>
<p>You could also enter a timestamp with each posted form and store this in a database, checking before processing for identical timestamps, it depends on the nature of your application and your personal preference.</p>
<p>Any comments/improvements welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/resubmitting-forms-upon-page-refresh-or-reload-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

