Hi Rableen,
There are few easier ways -
1. To do this using dispatcher, check this link - http://help.sap.com/saphelp_nw70/helpdata/en/7b/72092aaa1342c5a3af7ce0b9a11ff9/content.htm
2. You can reduce the timeout for user sessions, so they will be logged off if inactive.
3. Writing custom code which would give user an alert after certain time period & do auto logoff if user does nothing. Lots of threads available in scn to achieve this. For example see this one - http://scn.sap.com/thread/3307601
Cheers,
Sen