Php: page 3
Convert UTC/GMT or any time zone to local time in PHP
Wrangling dates and times can be a somewhat arduous task for all programmers. One very common requirement is to convert a time from one time zone to another. In PHP this is greatly simplified with the DateTime standard library classes and especially DateTimeZone. For this example let us assume we have a UTC date and time string (2011-04-27 02:45) that we would like to convert to ACST (Australian Central Standard Time). Read more โ
Idiorm and Paris 1.4.0 Released
After a lot of work and many contributions from valued community members Idiorm and Paris versions 1.4.0 have been released into the wild. You can download them now from their respective repositories or via Composer/Packagist. As you are probably aware from my previous posts Idiorm is a minimalist ORM that is targetted at PHP 5.2 and above. It combines a fluent query builder with a simple ORM interface to allow fast and easy access to databases over PDO. Read more โ
Improve PHP session cookie security
The security of session handling in PHP can easily be enhanced through the use of a few configuration settings and the addition of an SSL certificate. Whilst this topic has been covered numerous times before it still bears mentioning with a large number of PHP sites and servers having not implemented these features. To prevent session hijacking through cross site scripting (XSS) you should always filter and escape all user supplied values before printing them to screen. Read more โ
There are a number of things you can do to make a server more secure whilst protecting your hosted entities and their users. Here are just three of the many things I do on every new server I commission. I hasten to add that these are not necessarily the most effective or at the top of my list - they are just that: 3 things I set on new servers. Read more โ
The PHP project as a whole has been migrating to use git as its SCM of choice. This includes the core code and some PECL extensions such as BitSet and the sources for the PHP.net web properties like wiki.php.net Well now the PHP team have helped me to migrate the source of ssdeep to git, which means it is now also mirrored (where you can star it) to the official PHP github account. Read more โ
Idiorm and Paris 1.3.0 released - the minimalist ORM and fluent query builder for PHP
Idiorm is a PHP ORM that eschews complexity and deliberately remains lightweight with support for PHP5.2+. It consists of one file and primarily one class that can easily be configured in a few lines of code. There are no models to create, no convoluted configuration formats and there is no database introspection just a simple PDO connection string. However, having said this, Idiorm is very powerful and it makes most of the queries PHP applications require pain free. Read more โ
Unicode shortcut in Netbeans for React/Curry
In some of my code I use a PHP library called React/Curry and to save typing it uses a unicode ellipsis (โฆ) for a method name. Yes, that is right unicode method names can be legal in PHP! <?php $firstChar = Curry\bind('substr', Curry\โฆ(), 0, 1); See I told you so! Well that is great, but how do you type a unicode character into a Netbeans document? To save having to constantly copy and paste the โฆ character from a symbols list I have setup a very simple macro in Netbeans to print the character for me. Read more โ
Navigator: Geographic calculation library for PHP
Navigator is a PHP library for easily performing geographic calculations and distance unit conversions on Earth or any other spheroid. Currently it supports distance calculations between two coordinates using Vincenty, Haversine, Great Circle or Cosine Law. By default it uses the most accurate, but computationally intensive: Vincenty. To calculate the distance between two points on Earth in metres it is as simple as: <?php use Treffynnon\Navigator as N; $distance = N::getDistance(10, 81. Read more โ
Force URLs to lowercase with Apache rewrite and PHP
Canonical pages are an important aspect of maintaining a website and ensure that search engine rankings are not affected by any duplicated content. In *NIX based systems file names with varying capitalisation are treated as separate files. For example filename.txt is not the same file as FileName.TXT. This extends into the world of Apache where URLs are also case sensitive. So that means that we really should pick a case for our URLs and force all browsers to redirect to our chosen scheme. Read more โ
PHP extension writing: PHP Extensions Made Eldrich
PHP extension writing: PHP Extensions Made Eldrich Since writing my 15 Excellent Resources for PHP Extension Development post in September last year Kristina Chodorow of 10gen (MongoDB) has written an excellent four part article on writing PHP Extensions on her blog Snail in a Turtleneck. Read more โ