Imam Ghazali said:
“You will not be succesful in guarding the private parts except by guarding the eye from looking, the heart from contemplating, and the stomach from doubtful food and from satiety, for these things stir one’s desires and are the places where their seeds are sown.” 
Reflection: Protecting oneself from the harmful effect of sexual desires is one of the biggest challenges we are facing today. These desires are praiseworthy when directed towards one’s spouse, but are destructive when is it directed elsewhere. Ruined marriages, affairs, addictions and illicit relationships between practicing brothers and sisters, are just some of the negative consequences these desires can lead to if left untamed. In this quote, Imam Ghazali points out the main causes that leads one to the forbidden. They are:
Looking: While it might seem innocent, this is really where it all starts. Through an unlawful look the desires are excited and the person is tempted to follow it up with another look, or perhaps initiate contact with the one being looked at. Our brains are wired to stir our desires when we see a potential partner, which is one of the things that could encourage us to marry someone. The Prophet(ﷺ) advised, that one should look at a potential partner if there was a genuine wish to marry that person. But in our time we are being supplied with endless opportunities to look at the other gender, through adds, movies, pornography, tight clothing etc. The result is devastating for our spirituality and while recognizing that this is a challenge, which we will be rewarded for, we should never allow ourselves to excuse our conduct because we live in times of fitnah.
Contemplating: This might be something we don’t consider much in this regard. One might think, that as long as they protect their gaze, they will be safe from temptation. But many evils start with a thought, which stirs a desire, which leads one to act on that desire. The scholars disagreed on the permissibility of entertaining thoughts about doing haram, like committing zina for example, but if there’s a high likelihood that these thoughts could lead to haram, then it would not be permissible to entertain these thoughts. If such a thought occur, you should put it out of your mind and recognize that you will be rewarded by Allah if you refrain from acting on it. If one continues to think about it, even if considered permissible, there’s the risk that it leads to temptation which might end up in humiliation. The Prophet(ﷺ) said:
“It is not for the believer to humiliate himself.” They said: “How does he humiliate himself?” He said: “By taking on a trial which he can not bear.” 
Protecting the stomach: Interestingly, Imam Ghazali made a link between the stomach and the private parts. In his famous work, Ihya Ulum ad-Deen (“The Revival of the Religious Sciences) he treated excessive desire for food along with the sexual desires. This connection is not just a myth. Through history, specific foods have been known to increase libido and low libido is considered among the symptoms of malnutrition. Imam Ghazali supplies a spiritual dimension to this, by warning against doubtful foods and their effect on the desires. Many of the great scholars of Islam, especially the ascetics, were extremely careful about what they allowed themselves to eat. The least we should do to protect ourselves and our families, would be to make sure our income is halal. We also need to recognize, that while the assumption in terms of foodstuff is permissibility (except for meat), it is disliked to eat doubtful food and it could harm our spiritual wellbeing. Lastly, we should be moderate in the amount of food we consume, attempting to follow the Sunnah, unless there is a valid reason for eating more.
 Ghazali, Bidayah al-Hidayah (Quote taken from the English translation: “The Beginning of Guidance”, White Thread Press)
 Imam Ahmed, Tirmidhi, Ibn Majah and others narrated it.