I have tried setting the cookie lifetime to 86400 and configuring other settings from the magento backend but still doesn't work. I tried clearing the cache and somehow solves the problem for a few minutes then it won't work again. Please help.
Please do config as below
go to admin->system->configuration-> Web -> Session Cookie Management
Cookie Lifetime : 86400
Cookie Domain : .yoursite.com
Use HTTP only : yes
Cookie Path : /
Or Comment below code
Go to: Magento Folder/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
and comment out the following that starts at about line 78 as you see below.
/*
session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath()
$this->getCookie()->getDomain(),
$this->getCookie()->isSecure(),
$this->getCookie()->getHttponly()
);
*/