How to Avoid the Temptation of Women
Question

I have read the words of the Prophet (peace and blessings of Allah be upon him), “I have not left behind me any Fitnah (temptation) more harmful to men than women.” Narrated by Al-Bukhari, 5096; Muslim, 2740.
My question is: how can I save myself from this temptation, when I see it everywhere – in the street, on TV, on the internet, at work…?
Praise be to Allah.This world is the place of trials and tribulations
Allah has created man in a world of trials and tests, and He has made Paradise the abode of His friends and beloved ones, who preferred His pleasure over their own and preferred obedience to Him over their physical comfort. And He has made Hell the abode of those among His slaves who disobey Him and preferred their own whims and desires to the pleasure of their Lord. Allah says (interpretation of the meaning):
{Such is the Paradise which We shall give as an inheritance to those of Our slaves who have been Al-Muttaqun (the pious).} [Maryam 19:63]
{But as for him who feared standing before his Lord, and restrained himself from impure evil desires and lusts. Verily, Paradise will be his abode.} [An-Nazi`at 79:40-41]
And He says concerning the people of Hell (interpretation of the meaning):
{Then, there has succeeded them a posterity who have given up As-Salat (the prayers) [i.e. made their prayers to be lost, either by not offering them or by not offering them perfectly or by not offering them in their proper fixed times] and have followed lusts. So they will be thrown in Hell.} [Maryam 19:59]
 And He says (interpretation of the meaning):
{That shall be their recompense, Hell; because they disbelieved and took My Ayat (proofs, evidences, verses, lessons, signs, revelations, etc.) and My Messengers by way of jest and mockery.} [Al-Kahf 18:106]
{Then for him who transgressed all bounds, (in disbelief, oppression and evil deeds of disobedience to Allah). And preferred the life of this world (by following his evil desires and lusts), Verily, his abode will be Hell-fire.} [An-Nazi`at 79:37-39]
So the Muslim must strive to worship Allah and keep away from that which angers Allah, for Allah will not cause the reward the one who does good to be lost (interpretation of the meaning):
{As for those who strive hard in Us (Our Cause), We will surely guide them to Our paths (i.e. Allah’s religion — Islamic Monotheism). And verily, Allah is with the Muhsinun (good-doers).} [Al-`Ankabut 29:69]
How to avoid the Fitnah of women
One of the Fitnahs (temptations) with which we are tested is the Fitnah of women, as the Prophet (peace and blessings of Allah be upon him) said: “I have not left behind me any Fitnah (temptation) more harmful to men than women.”
There follow some of the methods by which we can avoid this temptation. We ask Allah to set the affairs of the Muslims straight.

Faith in Allah.

Faith in Allah and fear of Allah provide a safety valve and protect a person against committing prohibited actions and following his own whims and desires.
If the believer becomes aware that Allah is always watching and if he ponders the meanings of His names and attributes, such as the All-Knowing, the All-Hearing, the All-Seeing, the Watchful, the Reckoner, the Preserver, the All-Encompassing, that will generate fear of Him in secret and in public, and will put a stop to disobedience towards Allah, and will reduce the strength of desire that leads many people to commit prohibited actions.

Lowering the gaze and avoiding looking at prohibited things

The gaze can generate bad thoughts in the heart, which then lead to ideas and then to desires, then to will and resolve, and then inevitably to doing prohibited things. Think about the meaning of this verse which makes a connection between the first steps towards prohibited and the end result. Allah says (interpretation of the meaning):
{Tell the believing men to lower their gaze (from looking at forbidden things), and protect their private parts (from illegal sexual acts). That is purer for them. Verily, Allah is All-Aware of what they do.} [An-Nur 24:30]
Ibn Kathir (may Allah have mercy on him) said: “This is a command from Allah to His believing slaves, to lower their gaze and avoid looking at that which is forbidden to them so that they only look at that which they are permitted to look at.  If it so happens that a person’s gaze accidentally falls upon something prohibited, he should turn his gaze away from it quickly.” (End quote)

Warding off evil thoughts

Bad thoughts pose a danger to the heart… If a person dwells on them and does not push them away, they will develop into an idea, then into will and resolve, then this will inevitably lead to prohibited actions.  Beware of dwelling on passing thoughts; rather what you must do is to ward them off and crowd them out with good thoughts.
The treatment, then, is to ward off these passing thoughts and keep yourself busy with beneficial thoughts.

Marriage

It was narrated that `Abdullah ibn Mas`ud (may Allah be pleased with him) said: The Prophet (peace and blessings of Allah be upon him) said: “O young men, whoever among you can afford it, let him get married, and whoever cannot, let him fast, for it will be a shield for him.” (Narrated by Al-Bukhari, 5065)

Fasting for those who cannot afford to get married

– because of the Hadith quoted above, in which it says, “…and whoever cannot, let him fast, for it will be a shield for him.” (Narrated by Al-Bukhari, 5065)
Al-Qurtubi (may Allah have mercy on him) said:
“The less a person eats, the weaker his desire becomes, and the weaker his desire is, the less sins he commits.” (End quote)

Keeping away from bad companions.

The Prophet (peace and blessings of Allah be upon him) said: “A man will follow the way of his close friends, so let each one of you look at who he takes as a close friend.” (Narrated by Abu Dawud, 8433; classed as sound by Al-Albani in Sahih Abu Dawud, 4046)

Keeping away from places of temptation.

It is obvious that we are living in a society that is filled with temptation – media of all types, magazines, flirting in the marketplaces, satellite TV, the internet, etc… So you have to flee from all of these in order to keep your religious commitment sound.

Do not make your houses graves.

Make your house a reminder of obedience, not of sin. If a room is connected to sin for example, that will make a person commit sin repeatedly, because every time he enters that room he will remember the sin and may be provoked to commit the sin again. So he should make his room and his house a reminder of obedience to Allah, so when he enters he sees the Mus-haf which he reads, and he remembers praying Qiyam Al-Layl for Allah, and the regular Sunnah prayers that he offers in this room. Doing a lot of acts of worship in your house will make a connection in your mind between the house and doing good deeds, so you will do more and will think less of sin, and the calls of desire will grow less.

Trying to make the most of your time in worshipping and obeying Allah.

Time is one of the great blessings that Allah has bestowed upon His slaves, but there are many who are not making the most of it. It was narrated that Ibn `Abbas (may Allah be pleased with him) said: The Prophet (peace and blessings of Allah be upon him) said: “Two blessings which many people do not make the most of: good health and spare time.” (Narrated by Al-Bukhari, 64120)

Remembering the blessings of the Hereafter.

Particularly appropriate in this context is remembering Al-Hur Al-`Iyn and their attributes, whom Allah has prepared for those who are patient and steadfast in avoiding sin. This can help the Muslim to look away from these transient prohibited pleasures which only lead to regret and loss.
We ask Allah to help us to avoid temptation, both obvious and hidden. Praise be to Allah the Lord of the Worlds.
And Allah knows best.