Our Sponsors

Monday, 13 June 2011

Calculate distance between two points

So whilst working with Google Maps lately, I found this super-useful snippet that calculates the distance between two points, using longitdue and latitude.

Code:
function distance($lat1, $lon1, $lat2, $lon2, $unit) { 
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);

if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}

Usage:
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "k")." kilometers";

Credit: PHPSnippets.info

Sunday, 12 June 2011

Some PHP Best Practices


nb - Some tips may be contradictory, so please use these at your own risk :)

Friday, 10 June 2011

Ion_Auth for CodeIgniter

Today I am promoting the awesome third-party library, Ion_Auth, for CI.

It is a fully fledged authorisation library, allowing you to set up secured areas, user groups, profiles, the lot!

I have used it on several projects and it has yet to let me down.

http://codeigniter.com/wiki/Ion_Auth_-_Lightweight_Auth_System/

Tuesday, 7 June 2011

Adventure Game Update

I haven't had chance to work much more on my PHP Adventure Game as of late, however I will be free to start afresh on this project soon.

Due to my new found love for CodeIgniter, I will be rebuilding the game using this framework. Hopefully I can get to the same point I was at before, much quicker and the whole project itself will be neater and more robust :)

CodeIgniter

So I have been using CodeIgniter (CI) for the past 7 months and I am more then impressed!

Very well maintained Framework, with lots of available additional libraries and modifications by fellow CI Community peeps.

I am currently finishing a project using CI v1, however v2 has been released and is a bit tighter.

Stay tuned for more insights :)

Monday, 11 October 2010

PHP Adventure Game

So today I did some work on my PHP Adventure Game.

I am using it as an excuse to learn OOPHP and also to make something that I hope people will one day actually play!