In today's interconnected digital landscape, ensuring data security in transit is paramount amidst the constant threat of adversaries exploiting vulnerabilities in communication channels. This study introduces an enhanced Diffie-Hellman key exchange algorithm designed to bolster data encryption against Man-in-the-Middle (MITM) attacks. The objectives include the development of a novel Diffie-Hellman key exchange model to ensure confidentiality and integrity of data during transit, along with implementing measures to thwart MITM attacks. Additionally, the study integrates a time-based key expiration mechanism within the Diffie-Hellman framework to facilitate secure data transmission while enforcing user authentication. The proposed model was simulated using the Hypertext Preprocessor (PHP) programming language, enabling comprehensive evaluation of performance metrics such as execution time, computational overhead, security strength, and adherence to Burrows-Abadi-Needham (BAN) logic. Rigorous testing and analysis demonstrate the efficacy of the enhanced Diffie-Hellman algorithm in safeguarding data integrity and confidentiality during transit, offering a robust solution against evolving cyber threats.