Session Cookies between SSL and Non-SSL in CakePHP

CakePHP 2.0

If you use SSL (https, secure) for User login action in CakePHP, the session cookie by default works only for SSL connection.

<?php
class UsersController extends AppController {

    public $components = array('Security');

    function beforeFilter() {
        $this->Security->blackHoleCallback = 'forceSSL';
        $this->Security->requireSecure();
        parent::beforeFilter();
        $this->Auth->allow('login', 'logout');
    }

    function forceSSL() {
        $this->redirect('https://' . env('SERVER_NAME') . $this->here);
    }
}

So, when you do the login under a secure page/https, after a successful login CakePHP will save a session cookie under https protocol only, and by default will continue serving under https.

While this suits most requirements in practice, some people prefer redirect back to normal page/http afterwards to save server’s CPU. Using this default configuration, when you move to non-SSL (http) pages, the cookie is lost and the system will redirect you again to login screen. This may cause a loop of unsuccessful logins.

After searching for solutions from many resources, the answer is actually there in CakePHP’s Cookbook under “Session” topic.

http://book.cakephp.org/2.0/en/development/sessions.html

From the page:

CakePHP’s defaults to setting session.cookie_secure to true, when your application is on an SSL protocol. If your application serves from both SSL and non-SSL protocols, then you might have problems with sessions being lost. If you need access to the session on both SSL and non-SSL domains you will want to disable this:

<?php
Configure::write('Session', array(
    'defaults' => 'php',
    'ini' => array(
        'session.cookie_secure' => false
    )
));

Put the code above in core.php along with other directives.

Posted in Developments | Tagged , | Comments Off

Self-Healing Online Server Platform

Some practical issues with online application servers:

  1. A dedicated server may be too much for an online application — maximum resource utilization never reached and causing it wasting too much resources. This is especially a problem for a new/developing application.
  2. A dedicated server is not easily or quickly expandable when more resource is required.
  3. For small web site owners, like me, server crash means downtime and the time required to take it back online is unpredictable.

A popular solution for efficient resource usage is by using server virtualization (virtual servers/machines). Initially this solved the efficiency problem by putting many virtual servers into a single physical server. This way, we can add up virtual servers until near full resources of the physical server are used. Every individual virtual server can also be scaled easily.

Recently, a virtual server technology called Xen is developed to have a self-healing feature. This is possible by having a software controller to monitor the virtual servers running on several physical servers. If a virtual server is down, the controller will immediately move the virtual server to another running physical server. So, your server is in ‘always-on’ state and this solves the problem #3.

In practice, Virtual Private Servers (VPS) play a significant role in growing the Software-as-a-Service business. The provider can start by using a small VPS and upscale later when the application needs more resources as the business grows.

Posted in Business | Leave a comment

Smartphone Competition

So many things to consider in the competition for mobile handset market like whether it will be a QWERTY, touchscreen, or both. But it seems many people now also consider the operating system used and favor the ones with iOS or Android operating systems. So, it is the operating system choice and also the marketplace under the system. The following is the excerpt from the article at Fortune (CNN-Money):

Many questions about LG’s strategic choice needed answering. After all, Windows Mobile was a hastily cooked-up OS designed to keep up with Apple and Google. Microsoft had basically scaled down its PC-based Windows OS and squeezed it into a handset, making the OS painfully slow. Moreover, the problems with Windows Mobile were not restricted to speed. While in Barcelona, Ballmer was busy criticizing Apple’s App Store — not on product merit, but on the basis of Apple’s closed system. Ballmer said it was important that the App Store be open, because he viewed openness as a basic requirement.

Quite interesting.

Posted in Business | Leave a comment

Why I Choose Mootools over jQuery

Just my another opinion. When I realized that Mootools has the smoothest animation, it became my favorite Javascript library. jQuery is very popular, especially for its ease of use. But in my book, smooth effects is ultimately more pleasing, while it is not much more complex than others too.

See the demos of both libraries on GUI effect called ‘Accordion’ below (and yes, try clicking on the ‘headers’ to see the panels’ slide effects):

Mootools: http://mootools.net/demos/?demo=Accordion
jQuery: http://jquery.com/files/demo/dl-done.html updated to http://docs.jquery.com/UI/Accordion (checked: 2011-07-31)

Posted in Developments | Tagged | Leave a comment

Online Platform Independent Applications

I just saw the article at http://tech.fortune.cnn.com/2010/12/20/videogamings-online-explosion/ also says that online gaming applications are spreading (similar to my post about  ‘Computer Application Trend 2011′). The growing of this business may give only small contribution to the old-style-proprietary platform such as: Nintendo, Microsoft, or Sony, as they are not using those platforms. I believe this makes a new opportunity for this new expertise: server farm and cloud.

Moving further, I also see that thin clients will be used more. Mobile platforms (mobile phone handsets) and their operating systems will also be seen more in the market. So, client platforms such as iOS, Android, Chrome, and others (like Symbian and Bada), may be the way of the future for operating systems.

Don’t bother the big players, but see this as a good opportunity to grow. The market is growing fast.

Posted in Business | Leave a comment