Check if headers have been sent before starting a session

Check if headers have been sent before starting a session to prevent warning messages.