Using cURL in PHP to access HTTPS (SSL/TLS) protected sites

curl-https-padlock

From PHP, you can access the useful cURL Library (libcurl) to make requests to URLs using a variety of protocols such as HTTP, FTP, LDAP and even Gopher. (If you’ve spent time on the *nix command line, most environments also have the curl command available that uses the libcurl library)

In practice, however, the most commonly-used protocol tends to be HTTP, especially when using PHP for server-to-server communication. Typically this involves accessing another web server as part of a web service call, using some method such as XML-RPC or REST to query a resource. For example, Delicious offers a HTTP-based API to manipulate and read a user’s posts. However, when trying to access a HTTPS resource (such as the delicious API), there’s a little more configuration you have to do before you can get cURL working right in PHP.

Continued

Decoding Google Maps Encoded Polylines using PHP

I’ve talked about the Google Maps encoded polyline format before. While there’s some nice utilities for encoding polylines that take the work out of implementing it yourself, I couldn’t find many polyline decoders.

This made it somewhat tedious to decode them, as the only way to get the original list of points was to create a GPolyline and then pull out the points from that object. This is not ideal since the work must always be done on the client side with JavaScript and using Google Maps.

To solve this, I quickly ported the algorithm over to PHP from the JavaScript source. Please feel free to download/modify/use this script.

Continued

I’ve been busy

I haven’t been posting updates or writing as many articles here as I’d like to, and it’s mainly because I’ve been busy putting the final touches on a website I’m about to launch. I don’t want to give away too many details or build too much hype, because frankly it’s not that big of a project and was never intended to be.

However, it was a project that I intended to learn from, and in that regard, I think I’ve succeeded – and that’s really what I want to continue doing for the rest of my life. Furthermore, while the project was an exercise in improving my web and software development skills, the end result will also be something that I will actually use myself – not just some pointless academic exercise. Another nice effect was the experience of seeing a self-directed project come to fruition over the last few months – albeit at a slow rate, usually only several hours per week, but nonetheless I’ve improved my self-discipline as a result. Continued

CakePHP and error/exception handling

Copyright CakePHP

I’m currently using CakePHP and finding it to be quite useful. The “automagic” handling of tables is useful for basic relationships, though more complicated setups usually require manual work. The MVC implementation has also clearly drawn inspiration from Ruby on Rails, which may be advantageous to some, though this has no bearing on me. Though there are a few things that nag me about CakePHP (such as lack of a good testing suite, though that’s supposedly fixed in 1.2, which really should be marked as version 2.0), overall it’s a great framework that adds badly-needed structure to PHP and has saved me time.

One thing I’d like to see, however, is a proper exception handling model. I realize this would require making it PHP 5-only, but in my opinion, PHP 5 adds some sorely-need features, such as the aforementioned exception handling model and a class/object system more in line with other languages.

Continued