If one fears that they may sin by looking at pornography what precautions can they take to prevent it especially in situations when they are alone?

I would recommend diverting your attention to something else to keep your self busy in doing something productive.