put a plate switch conected to the gate on both ways? or use a proximity switch that activates the gate after you pass
The idea is to have it close automatically no matter if you're entering or leaving, but have it be opened manually.