Add session control function

Add code to control whether the session