Hello @kartik,
Try this:
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
// set data
$session->setData("device_id", 4);
// get data
$myDeviceId = $session->getData("device_id");
Make sure you include [Mage-root]/app/Mage.php befor calling the code above!
Hope it helps!!