It is narrated from Sayyiduna Abu Hurayrah (may Allah be pleased with him): Ka'b (may Allah have mercy on him) took hold of my hand and said: "Memorise two things from me: When you enter the mosque, send salam upon the Prophet (peace and blessings be upon him) and say: 'Allahumma iftah li abwab al-rahmah' (O Allah, open for me the doors of Your mercy); and when you go out (of the mosque), send salam upon the Prophet (peace and blessings be upon him) and say: 'Allahumma ihfazni min al-shaytan al-rajim' (O Allah, protect me from Satan the accursed)."
I say: Ibn Hibban recorded it in his Sahih as marfu' with the chain of al-Dahhak bin Uthman, from Sa'id al-Maqburi (may Allah have mercy on him), from Sayyiduna Abu Hurayrah (may Allah be pleased with him), that the Messenger of Allah (peace and blessings be upon him) said, and then he mentioned this same hadith, except that in place of "ihfazni" it has the words 'Allahumma ajirni' (O Allah, grant me refuge (from Satan the accursed)).
Al-Tabarani recorded it in 'Kitab al-Du'a' with the chain of al-Dahhak bin Uthman, from Sa'id al-Maqburi (may Allah have mercy on him), from Sayyiduna Abu Hurayrah (may Allah be pleased with him), that the Messenger of Allah (peace and blessings be upon him), and then he mentioned the full hadith, but in it are these words: "And let him say: 'Allahumma i'simni min al-shaytan al-rajim' (O Allah, guard me against Satan the accursed)."
I say: Ibn Majah recorded a part of it, from "When you enter the mosque" to the end, without the opening story, with a sahih (authentic) chain through Sa'id al-Maqburi (may Allah have mercy on him); likewise al-Nasa'i recorded it in 'al-Yawm wa al-Laylah', and al-Hakim also recorded it and graded it sahih al-isnad (authentic in chain).
Hadith Referenceإتحاف الخيرة المهرة بزوائد المسانيد العشرة / كتاب المساجد / 989
Hadith Gradingمحدثین:إسناده صحيح
Hadith Takhrij«بسند صحيح، من طريق سعيد المقبري عنه به، وكذا رواه النسائي في اليوم والليلة، والحاكم وقال: صحيح الإسناد» «أخرجه سنن ابن ماجه برقم: 773، وأخرجه المستدرك على الصحيحين برقم: 775، وأخرجه صحيح ابن خزيمة برقم: 452، 2706، وأخرجه صحيح ابن حبان برقم: 2047، 2050، وأخرجه البحر الزخار المعروف بمسند البزار 10 - 18 برقم: 8523، وأخرجه الأوسط في السنن والإجماع والاختلاف برقم: 1245»