Kohana 3, Internet Explorer & Regenerating Sessions

Preamble: This is not a Kohana bug per sé, it affects all PHP applications that use cookies when viewed in certain browsers (particularly IE) and further reading can be found at on the PHP.net site. The first part of this post discusses the symptoms of the issue that are specific to Kohana but the solution will be relevant to all.

Background

For quite some time now, I have followed the naming convention

http://[site]_dev.[server].creativeintent.co.uk

for my development sites. It seemed a nice, simple (and obvious) way to differentiate between production and development sites on our servers.

We've been following this pattern for quite some time now without issue. Chrome is our browser of choice in the Creative Intent studio because it offers such a powerful range of tools to us during development. However, it would seem that our good friend has been holding our hand and leading us down a dangerous path by being just a little too helpful.

The Symptoms

The issue first cropped up at 0930 this morning after we'd presented initial access to a client for their ecommerce site which we have been developing. This particular client already runs a popular online shop on our CaffeineCommerce platform but shortly after emailing them their access details for the development site, we'd received a support request..."I can't login!".

We double checked the authentication process to the administration area from our desks and everything seemed fine. Cue nearly an hour of telephone support, "Are you sure that you're on the right domain, entering the right username and password...?", clearing caches, cookies and restarting computers and servers. No joy! So we moved onto debugging. Sure enough, the login details were correct and if I pasted them into my browser they worked!?

"Which browser are you using again?" ... "Internet Explorer" sigh

What's happening under the hood?

So, I booted up VirtualBox and opened a Windows XP VM, tested in Internet Explorer and sure enough the log in failed. However, opening the production site and logging in...no problem!

I am rather embarassed to say that it took me quite some time to understand quite what was happening here. The request was getting from my controller to the Auth module, successfully and the Auth module in turn was returning a positive result and saving the user into session. Great.

Next, the controller takes over and redirects the user into the administration area, only by this point the Auth module reports that we are no longer authenticated and redirects us back to the log in page BUT only in Internet Explorer!

What is this voodoo curse?

Everything is pointing towards a bug in the session management. There used to be a known issue in Kohana 2.3.X whereby some installations would regenrate the session on every page load. I don't think that anybody ever discovered why this happened but eventually the development team simply removed the automatic regeneration (2.3.4 onwords), leaving up the the developer to manage this manually. I'm using version 3.X so this can't be the problem, sure seems similar though.

So what else is different between the production site and the development site? Well there's an underscore in the server name part of the URL but that wouldn't cause the session to regenerate on every page load in Internet Explorer...surely? Would it? Yup.

Solution

Quite simply, the solution is to avoid the use of underscores in your server name where possible. The use of underscores in domain names is, in fact, not valid and although some browsers such as Chrome and Firefox will allow you to plough away without issue, there are still many browsers that will throw up unexpected errors that may take some time to debug.

Listening Post: Visualising the Internet

On a visit to The Science Museum in London back in 2008, I was fortunate enough to stumble upon a mesmerising exhibit situated in a dark corner of the first floor. What's sad is that as I sit and watch in awe of the amazing world portrayed in the hundreds on miniature displays, I am aware of other visitors that enter the room and leave moments later without giving a brief consideration as to what it is they are witnessing.

The Science Museum is a fun and fantastical day out for anybody. Over the past few years, I've visited the museum alone, with my wife and also with the in-laws. It's always enjoyable, the ever changing exhibits providing an amazement of education and despite numerous visits I am still left for lack of words at the interactive elements provided throughout the floors.

Despite all of this, my favourite area of the museum is not easy to find. It's not well advertised and for those that do stumble across its home, well, at first it can seem a little dull. The exhibit that I have come to adore with such great interest is Listening Post and I was truly disappointed to learn this weekend that the exhibits sparkle will come to an end as we welcome in 2012. With this in mind, I would encourage anybody with an interest in the Internet, be it for work or play, to take a day out of their busy schedule to visit The Science Museum and to spend a moment of their lifetime to experience the Internet in the truly unique way that only Listening Post can portray it.

Many a time have I tried to describe the wonderment of Listening Post to friends and family but I can never find a way to justly recreate the awe and the atmosphere, the overall experience. I will attempt to describe the experience to you in my own words but first, here is how the exhibit is described by its founding artists;

Listening Post is a 'dynamic portrait' of online communication, displaying uncensored fragments of text, sampled in real-time, from public internet chatrooms and bulletin boards. Artists Mark Hansen and Ben Rubin have divided their work into seven separate ‘scenes’ akin to movements in a symphony. Each scene has its own ‘internal logic’, sifting, filtering and ordering the text fragments in different ways.

By pulling text quotes from thousands of unwitting contributors' postings, Listening Post allows you to experience an extraordinary snapshot of the internet and gain a great sense of the humanity behind the data. The artwork is world renowned as a masterpiece of electronic and contemporary art and a monument to the ways we find to connect with each other and express our identities online.

One of the most difficult components to describe to people is the environment in which the experience takes place. It is very hard to imagine it simply from hearing it described and that's simply because the user interface is so unbelievably simple and yet so complex at the same time. With that in mind, I have included an image from The Science Museum's website below that will help to set the scene.

Lp_06_744px
Image sourced from http://www.sciencemuseum.org.uk

What makes Listening Post so wonderful is that it provides its guests with an alternative window to the Internet, a viewpoint which we rarely step back and observe. As a child of the 80's, I grew up through my early years without the Internet. Widespread access to the Internet started to appear when I was in my early teens although we'd had access to a restricted world wide web at school for a few years. It must have been around 1998 when we got access to the Internet at home for the first time, through a 56.6Kbps dial-up connection to AOL. Many of you will have scoffed at the mention of AOL, I certainly cringed as I remembered those days, but this was my first independent experience with the Internet and the start of a very exciting relationship with technology that most of us share today.

One of the very first experiences I can remember of the web, and AOL specifically, is that opportunities that it offered to chat with people virtually anywhere in the world. It was amazing, as a teen, to sit on the PC and be chatting in real time with people from either coast of the USA, Canada, Australia and beyond. In time, this evolved into matches of online pool at Yahoo! Games. As the internet has continued to mature, online chat, at least in real time, has started to fade out. This is due in part to the growth of online communities and social networks and also, somewhat sadly, due to the threat to people's privacy that has become apparent.

Maybe it's my fond memories of the chatroom that have led to my love of Listening Post. In simple terms, its creators have written a computer program that crawls the internet and harvests unsuspecting surfers' chat dialogue from the public chatrooms that still exist and the ever popular internet forums. The collected data is then interwoven into a mellow patchwork performance of stinted sentences that is as raw and honest as its author intended.

As the audience sits on the contemporary benches of the dark auditorium, waiting in anticipation, the relaxing music begins and the familiar clak-clakety-clak of a train station timetable board begins the show. The miniature black LED screens begin to light up and glow an alluring green, filling with words, phrases and abbreviations. The computerised voice begins to read a selection of the hundreds of phrases flashing across the displays, "I am 17...I am Mexican...I am 21/M/UK...", nothing unusual so far. But as we continue, it doesn't take long for a familiar tone to creep into the tale, "I am horny...I am looking for a hot chat...I am going to kill him".

The show that we are witnessing is pulling a selection of chatter containing the opening expression "I am..." and it very quickly becomes clear that the feed is uncensored and not only that, it reaffirms and reality that the internet is 90% sex and violence. With this in mind, don't fear that Listening Post is some sort of sick wonder. You have to see it to believe it. Altogether, there are seven separate shows that cycle through over a thirty minute period and each performance is totally unique. They'll spark intrigue, laughter and bemusement as you learn new abbreviations and watch the chatter of the web unfold, live, before your very eyes.

It's unlikely that I'll get the chance to visit The Science Museum again this year and so I may have experienced my final showing of the show. I do not know what the artists have planned for the exhibit once its time at The Science Museum draws to an end but I hope that it will live on somewhere so that we can continue to enjoy its wonderful aura. Whatever its future, I'd like to thank Ben Rubin and Mark Hansen for sharing their work with us and would urge you to visit the exhibit on the first floor of The Science Museum and witness it for yourself before it closes at the end of December 2011.

Building a Nanode: Day Two

Photo1
The majority of the components are fixed onto the PCB and the next step in the build process is to test the power supply rails in order that we don't fry the IC's. As I don't have a Multimeter I have hit a bit of a stumbling block!

With a multimeter and 5V USB to FTDI connector on order from Farnell, I shall take a break to catch up on other projects.

Building a Nanode: Day One

2e81de9b5b4e2c6168e00c87d74c7de5
Over the past few weeks I've been developing an iPhone app at Creative Intent for an entrepeneur with an interest in solar and other renewable energies. Following the launch of UK Solar Survey, I was introduced to James Smith and he invited me to join a bunch of nerds with an interest in solar and renewable energies at the Homecamp 4 "Hack the House" event at C4CC in London. And so, on Saturday 29th October, I downed tools and jumped on the train to London with the aim of meeting some new friends and showing them our latest iPhone app.

tl;dr This post is quite long and goes into some detail about the Nanode and how I was introduced to it. You'd be forgiven if you didn't want to read the whole post and so, in short, I'm building a Nanode kit and I'll be posting details of my progress and experience.

My introduction to Nanode at Homecamp 4

Homecamp wasn't quite what I was expecting it to be. I'd been expecting an auditorium with a big projection screen on stage and industry professionals on stage enlightening the captive audience with news of innovative products being released to the mass market in the near future. I couldn't have been more wrong! C4CC is a great venue but it's far from an auditorium, it's a "cozy" little hub tucked down a back street in Kings Cross; the projection screen was a wall with a pillar running down the middle. But somehow, all of this helped to set the mood for what turned out to be a fantastically exciting and informal get together of hardware builders, software developers and energy saving enthusiasts from all over the UK.

It very quickly became clear that the majority of people attending were very passionate about monitoring and improving energy use in the home and that many of these dedicated guys and girls had spent many years "hacking" the appliances in their homes with Arduinos and other custom electronics with amazing results. One particular component appearing in almost every presentation, demonstration and discussion was the Nanode. Until this moment I'd never heard of a Nanode, I had no idea what it was or why I needed one but it sure did look cool!

So, what is a Nanode?

In short, a Nanode is a variant of the Arduino project. It's a microcontroller that allows the user to customise the circuit board and use software to program it to do just about anything you could imagine. The Project Nanode entry on the London Hackspace website describes it as,

Nanode is an open source Arduino-like board that has in-built web connectivity. It connects to a range of wireless, wired and ethernet interfaces. It allows you to develop web based sensor and control systems - giving you web access to six analogue sensor lines and six digital I/O lines. It costs under £20 as an easy build it yourself kit. Nanode was designed with Hacking in mind.

A few of my friends have been playing around with Arduinos lately and I never really joined in on the fun and geekery. My fellow Ruby nerd, @MrJaba has been experimenting with an Arduino project that allows him to play the timeless classic "Pong" on his television using a Nintendo Wii controller, very cool.

Whilst the possibilities are near endless, the Nanode projects that I've come across since Homecamp seem to focus on using a network of the kits to monitor and control energy usage in the home. I've not yet decided what to do with my Nanode but I'm sure it'll get lonely sitting on its own and so I hope that it'll be joined by a family of Arduinos and Nanodes to perform some worthwhile task.

Electronics 101: Remembering how to solder

Unlike most of the Arduino kits that are available on the net, the Nanode comes in a pink plastic bag as a mash of unsoldered components and a PCB (printed circuit board) and so this, ladies and gentlemen, is where my adventure begins.

Many moons ago, back in high school (circa 1999), I learned how to crudely solder a selection of electrical components to a PCB and I've not touched a soldering iron since. After appealing for help on Twitter, another techy friend of mine @DanHigham pointed me in the direction of Farnell where I managed to pick up a soldering kit and a very cool "third hand" which were dispatched immediately and delivered next day.

In order to remind myself of the basics, I found an amusingly drawn comic strip by MightyOhm which does a brilliant job of describing the basic steps for soldering electronic components. I'd recommend this strip to any wannabe kit builders who are in need of a refresher.

4b63f7ba063858ca6e1d0a5ff515974c

And so, armed with my shiny new soldering equipment, my bag full of resistors, capacitors and many other components I propelled myself into the project with great enthusiasm. The Nanode step-by-step building guide suggests that it shouldn't take more than a couple of hours to complete the build process and to have the board ready for programming but, being a beginner, it took me that long to fix the first of the 10R resistors into place! Well...maybe not quite that long but I eventually got the hang of the soldering process and soldiered on.

With the first evening drawing to a close, I've managed to attach all of the resistors on the PCB along with the IC units. As a relative novice when it comes to electronics (and hardware in general) I am using each step of the build process, not only as a step to completing the build, but also as an opportunity to study each of the components, what role it has to play in the world of electronics and ultimately its role on the Nanode PCB.

You can find an artsy-fartsy snap of the PCB so far at the top of the post. Extra credit goes to anyone that the can spot the annoying flaw in the resistor line-up, leave a comment if you spot it.

What next for Nanode #0899?

Over the next few evenings, I hope to continue with the build and become the proud owner of a funtioning Nanode. What to build with the finished article is open to discussion and I'd love to hear you thoughts and ideas no matter how complicated, crazy or pointless, just dump them in the comments section below. Following the popular theme of home energy monitoring and saving, I've been pondering constructing a thermostat for the Creative Intent office that will monitor the temperature and time/day of the week in order to control the lighting (our only heat source at present) and have the office warm for us as winter draws in.

Another possibility that I hope to explore involves a network of Nanodes uploading data to the pachube service which allows data to be collected and extracted via API. This would open the opportunity to build web apps, iPhone apps and the like to display data and control electronics remotely in order to reduce energy use.

If you find electronics interesting, then you may want to check back later, or even better subscribe to receive updates on the project. I shall endeavour to post progress, interesting tidbits and some useful pictures as I solder, code and learn my way into Nanode (and Arduino) paradise.

If you have any ideas, corrections, criticisms that you would like to share then please do so by commenting below and if it helps in anyway I shall make sure to credit you in a future post.

Siri: a very impressive work in progress

Last Friday saw the release of the iPhone 4S in stores across the UK. I happened to be in town and spotted that the Vodafone shop on the High Street had the new handset in stock and so, I treated myself to a little impromptu upgrade!

What's impressed me most, so far, is the speed of the processor and how smoothly it runs the exciting iOS5. Having taken part in Apple's betas, running iOS5 on an old 3GS for the past few months, I'd gotten used to a rather disappointingly sluggish interface. But with the new handset comes a new lease of life, my iPhone is like a spring chicken.

And so, to Siri

If you aren't familiar with the new Siri concept that Apple have introduced to the the iPhone 4S, then check out the videos on the Apple website. The general concept is not new. Many companies have tried and ultimately failed to implement a voice controlled interface over the past few years.

Having played a little with Siri and having gauged opinion on the internet, it seems that Siri, in it's present format, is fun. A novelty. But not particularly useful...yet. Knowing Apple, Siri will not be left to rot. History has shown that Apple will release a product in it's basic form to generate hype and then over the coming months, a number of tweaks and additions will be made in order to maintain that level of excitement and chatter.

For UK users, many of Siri's more useful functions such as finding a business, calling up directions etc are met with a dull "I'm sorry Matt, this service is only available in the USA." As disappointing as this is, I'm sure that it'll be opened up to UK users shortly.

API hooks for third-party apps? 

What I'd like to believe is that Apple will provide API hooks to use developers so that we can hook Siri into our own apps. Its level of voice to text accuracy is impressive and I cannot imagine that it'd be massively difficult to open the service up to third-parties for use. I'll be keeping my eyes open for more news and keeping my fingers crossed that we might be able to operate the likes of UK Solar Survey and Invoice Agent by voice in the very near future!

Mobile apps leading the way for UX best practice

Having spent a large part of this evening preparing the foundations for a large UX review that we're conducting, it struck me how mobile frameworks, such as Cocoa for iOS and the Android SDK, are setting an exciting precedent for user experience.

Over the past few months, I've had the pleasure to work with native iOS and Android projects. On returning to web based app development, it has struck me how none of the common frameworks seem to put an emphasis on encouraging even the most basic of UI hints that the mobile frameworks insist upon.

The most strikingly obvious omission from the majority of everyday applications is what Apple refers to as the 'first responder' and you've probably never considered it up until now. If you have an iPhone or Android device, then you'll notice that when you open an app that requires an action, maybe a log in, the first input field is selected and the keyboard is on screen ready to go. Simple, right? So now open up one of your favourite websites, or maybe one that you've built...does it readily select the field that you're most likely to want. With a few exceptions, probably not.

Why not? Well, the mobile frameworks encourage the developer to provide a first responder out of the box but, to my knowledge, no web frameworks do so. It's a very simple UI tweak to achieve with a little bit of JavaScript, the focus() function is perfect if you have jQuery at your disposal.

It's really quite surprising how such a seemingly trivial afterthought can make your web app seem much smoother and easy to use so think about adding it to your apps in the future. There are a number of other simple tricks that mobile apps bring to the table that could help to improve usability of your web app too but maybe I'll talk about them in a later post.