Sort order issue in expressionengine 1.x

You might noticed the issue for sorting stuff in expressionengine cms to show entries if you’ve worked with this, that is if you’ve a custom field which stores number value and later you want sort the entries by that field – the entries sorted in wrong order! If you didn’t noticed that yet, explaining…

Let you have a custom field named “display_order”. This field stores integer value. Later you’ve tag like bellow to show entries in specific display order by this field –


{exp:weblog:entries  channel="channel_name"  orderby="display_order" sort="asc"  limit="15"}
content
{/exp:weblog:entries}

Above code pulls data in wrong order. Because Expressionengine creates varchar type field in table for every custom field. So if an entry has value 2 for display_order and 10, the entry with value 10 will comes first as mysql query treats them as string.

For this, you can do a quick trick. First find which field is created for the custom field you created, as per above example find out the field created for custom field “display_order”. Lets say table field for this custom field is field_id_20. Alter this field as integer type. So prepare a query like below and execute –

ALTER TABLE exp_weblog_data CHANGE `field_id_20` `field_id_20` INT(11) DEFAULT NULL

So, now see – issue is fixed ;)

ExpressionEngine Addon to track visit for specific pages

A few days back someone told me that he wants to track page visits of few selected for his ExpressionEngine site. To do that i built an extension and a module. You have to add the pages that is needed to track from module. I used sessions hooks to fire extension method that track/store visits info so later you can see the time to time visits info from module.
Continue reading

Sessions hook issue in ExpressionEngine Extension

I was creating a custom extension of expressionengine 1.6.x version where i tried to use sessions_start and sessions_end hooks but i was facing problem with $SESS global var, it was not loaded to extension method. The method was something like -

function do_something(){
	global $SESS;
	
	print_r($SESS);
}		

I wasted about 1/2 hours with this but no clue why this happened. Later i saw that, this hook is called with instantiated object(session) $this as parameter, so later i defined that function as –

function do_something($sess){
	print_r($sess);
}		

It solved and shows session data. Its very easy but sometime time wasting issue. Hope this will help EE community.

Email address verification/validation php class

Let you want to validate an email address using php, address is abc@yahoo.com, if you use regular expression, it will pass validation properly but we know – this is not a real email address. So we need to check if an email address is exists or not – it can be done. I’ve created a php class that verify email address. Let me show you how to use this class – Continue reading

Cakephp cookie doesn’t expire even after browser close?

If you used CakePHP framework to build application and used Auth component for Authentication – you might face few cookie related problems. One is – If you close browser without log out – it doesn’t expire that is, browser kept cookie for ever and you never logged it. This is the very serious issue. You may updated your security level to high to solve this iisue but this causes the session id to be regenerated on every request. This does make it very easy to lose your legitimate session though, and its excessive and costly – we don’t need that though. So i was searching for a easy and cheap solution – how to solve this issue but there are very less resources related to this problem. Later i found a nice solution on cakephp site! that is –

Set security level to midium rather than high on core.php

Configure::write('Security.level', 'medium');

Define custom session handling method rather than database or php. To do this, find out the collowing line in core.php

Configure::write('Session.save', 'php');

Updated the above line to

Configure::write('Session.save', 'my_session_handler');

So you specified your custom session handling preferences, now create the custom session handling file with following contents –

// app/config/my_session_handler.php
//
// Revert value and get rid of the referrer check even when,
// Security.level is medium
ini_restore('session.referer_check');

ini_set('session.use_trans_sid', 0);
ini_set('session.name', Configure::read('Session.cookie'));

// Cookie is now destroyed when browser is closed, doesn't 
// persist for days as it does by default for security
// low and medium
ini_set('session.cookie_lifetime', 0);

// Cookie path is now '/' even if you app is within a sub 
// directory on the domain
$this->path = '/';
ini_set('session.cookie_path', $this->path);

// Session cookie now persists across all subdomains
ini_set('session.cookie_domain', env('HTTP_BASE'));

Hopefully this configuration will be ok, tweak configuration as needed.