Saturday, December 29, 2012

How to detect iPhone, iPod or iPad using javascript

Most of the sites have a mobile version now a days. In fact they have multiple mobile versions of their site as screen size varies between phone and tablet. To have a mobile version for your site, you need to detect the client first. Detecting client can be done either on the server side (using your preferred scripting language) or the client side. I am showing here how you can detect it on the client side using Javascript. After detecting the client type, you can render an appropriate version of the site. Even you can use this technique to make your jQuery plugin mobile compatible.
var client;

if( navigator.userAgent.match(/iPhone/i) )
{
   client = 'iPhone';   
}
else if( navigator.userAgent.match(/iPod/i) )
{
   client = 'iPod';   
}
else if( navigator.userAgent.match(/iPad/i) ) 
{
   client = 'iPad';   
}

Friday, December 21, 2012

How to prevent back button from showing data after logout

In a secure web application where user has to login to see contents, it is not desirable that previous page(s) can be seen using browser's back button after a user has logged out. This can happen if you allow caching for your secure pages. The solution is easy. You need to set the cache-control and expiration date headers for your secured pages. The expiration date should be set to a past date so that it expires immediately. Here is an example:
Cache-Control: no-cache
Expires: Fri, 31 Dec 1990 12:00:00 GMT

How to install ruby 1.9 on CentOS 5

Recently I had to install ruby 1.9.1 on a CentOS 5 machine. I had a hard time in finding the right commands to do this simple task. So I am sharing the steps here:
cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz
tar xzvf ruby-1.9.1-p376.tar.gz
cd ruby-1.9.1-p376
./configure && make
sudo make install

Tuesday, December 11, 2012

phpMyAdmin automatic logout problem: No activity within 1440 seconds

One of the very few annoying features of phpmyadmin is the automatic logout after inactive 1440 seconds. I guess all users of phpmyadmin has faced this problem. The remedy is pretty easy. First go to "phpmyadmin" directory. Open the file named "config.inc.php" and add the following line:
$cfg['LoginCookieValidity'] = 3600 * 24; //24 hours
This will make the default time of 1440 seconds to 24 hours which is good enough I guess. Of course you can use any amount of time you want.