How to Make Web Pages Fit and Scale Nicely on Android Web Browser


Category : Android, CakePHP, PHP, Software development, web

I just released an Android version of my Cats Idol pet project – it lets you browse through photos of cats submitted by other people, rate the cats, and set the photos as your Android wallpaper.

One of the things I wanted to do was to provide users with the ability to upload photos straight from their phone. I decided that a web interface would be the easiest way to go at it. So, my application has a button called “Add cat” that launches the Android web browser with a URL of my server-side CakePHP-based upload HTML form.

The Problem

Then I ran in to a problem -  The HTML upload page was “zoomed out” on android, seemed like the browser did not scale the HTML properly and you needed a lot of zooming in order to work with it.

I thought this was a problem with my android code but found that it was actually a server-side issue.

After some digging, I found a solution to this issue.

The Solution

Adding these two Meta Tags in the head Tag of the HTML page solved this issue:

<meta name="HandheldFriendly" content="true" />
<meta name="viewport"
                 height=device-height, user-scalable=no" />

In CakePHP I added these Meta Tags to the mobile.ctp layout so it will affect all pages using the mobile layout.

Using these Meta tags fixed the way Android showed the HTML web page – The page looks zoomed-in and fits the screen very nicely:

Integrating CakePHP with Facebook Graph API


Category : Facebook, Open source, PHP, Wordpress

I just move my site (Cats Idol) from Drupal to CakePHP. It has definitely been a good move – in two weeks, working at night, I have gain a lot of control and flexibility I needed and did not have in Drupal.

CakePHP is an easy to use and agile development framework that provide an MVC,  a great ORM, and other useful tools for rapid application development.

But more on that in a different post..

Another major feature I needed was integration with Facebook:

  1. I wanted to use Facebook Auth and provisioning rather than t write it myself
  2. I wanted users to be able to comment and Like content on the site
  3. I wanted to publish content on users wall when they add content to Cats IdolCakePHP : the rapid development php framework

I found a very useful plugin, developed by Nick Baker, which provides this functionality and more.

So check the plugin here.

And you can see a demonstration of it in action here.

And CakePHP app integrated into Facebook here.

Thanks Nick, Great Job!

PHP foreach is by default by value and not by reference

Category : PHP, Software development

It is a little wired for Java and .NET developer, but PHP by default returns a copy of the iterated array item when running a foreach statement.

From the official PHP site – Note: Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don’t rely on the array pointer during or after the foreach without resetting it.

Here is a wrong way to manipulate an item in an array:

$arr1 = array(1, 2, 3, 4);
$arr2 = array(1, 2, 3, 4);
$arr = array(arr1,arr2);
foreach ($arr as $value) {
   //add an element to the inner array 
   $value[] =  5;

The $value is a copy of the item and the changed do not affect the item in the array itself.

Java and .NET developers, like myself, scratch their head and say “why doesn’t the foreach work?” or “what doesn’t the items in the foreach change?”

the answer is you need to use the & sign to let PHP know you need a reference rather then a value.

So here is the correct way to do the same thing:

$arr1 = array(1, 2, 3, 4);
$arr2 = array(1, 2, 3, 4);
$arr = array(arr1,arr2);
foreach ($arr as &$value) {
    //add an element to the inner array 
   $value[] =  5;

CakeOTP 1.1 – User Registration with One Time Password for CakePHP Released

Category : CakePHP, New Release, Open source, PHP, release, Security, Software development

CakeOTP is a reference implementation of User Registration with a secure, table-less and expirable implementation of One Time Password for the popular CakePHP development framework.

New in CakeOTP release 1.1

1) Automatic login process, after the account activation- The user is automatically logged into the site and is redirected to an internal page, immediately after activating his/her account.
2) User email validation.

Download this release here.

Checkout the Online Demo, project page and getting started page.

How to Connect IPWEditor to the Server Side


Category : ajaxdo, IPWEditor, JavaScript, PHP, SAAS

I have been getting multiple support requests from developers who want to save the data edited in IPWEditor on the server side.

Saving information in the server-side is a server-side feature and out of scope for IPWEditor (which is a client-side JQuery plug-in), moreover, it is programming language depended – a java developer might handle this differently from a .NET or a PHP developer.

Despite all that, I will try to give general guide on how it is done, I will be using PHP for the server-side examples but you can use any server-side programming language you prefer.

Continue Reading

Security issue in CakePHP code documentation


Category : CakePHP, Open source, PHP, Security, Software development

I have been using CakePHP for a long time now and enjoy every second. It provides a productive, easy to use and well document platform for PHP application. The key advantages for me are – transparent OR mapping, a strong Model View Controller framework, and tons of extra utilities that make your life better.

I have came across a possible security issue in one of cakePHP code examples. This section of code is responsible to authorize or un-authorize clients access to a certain action (MVC flow)

action == 'delete') {
            if ($this->Auth->user('role') == 'admin') {
                return true;
            } else {
                return false;

        return true;

The major security rule this code is breaking is – never ever have ‘return true’ as a default for an authorization method.
Continue Reading

CakeOTP 1.0 – Secure, Expirable, Table-less One Time Password for CakePHP Released

Category : CakePHP, Open source, PHP, release, Security, Software development

CakeOTP is a secure, table-less and expirable implementation of One Time Password for the popular CakePHP development framework.

A one-time password (OTP) is a password that is only valid for a single login session or transaction. It is commonly used in the internet for registration and password reminder process in which OTPs are provides to the user in a form of a link that the user uses to access in order to create/reset his password.

The problem is that most one-time password implementation involve maintaining additional database tables and batch process that handle the persistence and expire date of the one time password. This adds complexity and reduces performance.

CakeOTP is a simple and clean implementation of one time password. It reduces complexity by removing the redundant SQL calls and DB batch maintenance while still keeping the one time password secure and expirable.

Download this release here.

Checkout the Online Demo, project page and getting started page.

Feel free to post comments and questions.

CakeOTP 0.1 beta release – One Time Password Reference Implementation for CakePHP

Category : CakePHP, Open source, PHP, release, Security, Software development

I have started to implement the algorithm for tableless, secure One time password.

Here is a link to the Demo, and here is a link to the beta release.

The only thing you need to do other then the regular cakePHP setup is to create a user table (used by the CakePHP Auth component):

  `id` int(11) NOT NULL auto_increment,
  `username` char(50) default NULL,
  `password` char(40) default NULL,
  PRIMARY KEY  (`id`)

Continue Reading

Make ThickBox Work with Other JavaScript Libraries / Resolve ThickBox Conflict Issues


Category : JavaScript, jquery, Open source, PHP, Software development

ThickBox is a cool visualization tool based on Jquery JavaScript library. ThickBox helps you display photos in a cool way and is useful in many web projects.

The problem

ThickBox does not work when the HTML pages has other JavaScript libraries such as Mootools.

Debuging the error reveals this:

$(domChunk) is null

Continue Reading

Most Useful / Best Drupal Modules

Category : Drupal, PHP, Software development, Tips, web

I have recently upgraded my cats idol site to Drupal 6 and enhanced its functionality. I have also created several other sites (including this site) using the following set of useful Drupal modules.

Here is my list of useful (AKA Best IMHO) Drupal modules:
Continue Reading