Accepting cookie and maintaining session but not working properly