This has more to do with your architectural design of your door as with any code. What kind of door do you have (sliding, rotating, …)? How should it be opened? How should it be closed? Ask detailed questions. It’s really not clear what exactly you want.
The usual way to detect if th player is in front of a door / object / … is to use a trigger. There are tons of tutorials out there.