It is narrated from Sayyiduna Abu Usayd al-Sa'idi (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: "When one of you enters the mosque, let him give the greeting of peace and say: 'Allahumma iftah li abwaba rahmatik' (O Allah, open for me the doors of Your mercy). And when he leaves the mosque, let him say: 'Allahumma inni as'aluka min fadlik' (O Allah, I ask You of Your bounty)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4317
Likewise (through another chain), except that he did not say: "let him give the greeting of peace."
The wording of the greeting of peace in it is mahfuz (preserved).
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4318
It is narrated from Sayyiduna Abu Usayd al-Sa'idi (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When one of you enters the mosque, let him send the greeting of peace upon the Prophet (peace and blessings be upon him), then say: 'Allahumma iftah li abwaba rahmatik' (O Allah, open for me the doors of Your mercy). And when he leaves, let him say: 'Allahumma inni as'aluka min fadlik' (O Allah, I ask You of Your bounty)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4319
Rabi'ah bin Abi Abd al-Rahman (may Allah have mercy on him) narrated it with some additional words, namely: "Let him give the greeting of peace, or send blessings upon the Prophet (peace and blessings be upon him)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4320
It is narrated from Sayyiduna Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When one of you enters the mosque, let him send the greeting of peace upon the Prophet (peace and blessings be upon him) and say: 'Allahumma iftah li abwaba rahmatik' (O Allah, open for me the doors of Your mercy). And when he leaves the mosque, let him send the greeting of peace upon the Prophet (peace and blessings be upon him) and say: 'Allahumma ajirni min al-shaytan al-rajim' (O Allah, protect me from Satan the accursed)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4321
Hadith Gradingمحدثین:حسن
Hadith Takhrij«حسن۔ ابن ماجه 773، ابن خزيمه 452-2706»
Sayyiduna Anas bin Malik (may Allah be pleased with him) said: "When entering the mosque, put the right foot in first, and when leaving, take the left foot out first. This is the Sunnah."
Only Shaddad bin Sa'id Abu Talhah al-Rasibi narrated it, and he is not strong.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4322