What are the potential security risks of passing user credentials through the URL using MD5 encryption in PHP?

Passing user credentials through the URL using MD5 encryption in PHP can pose security risks as the credentials are visible in the URL and can be easily intercepted. To mitigate this risk, it is recommended to use HTTPS for secure communication and avoid passing sensitive information through the URL. Instead, consider using sessions or cookies to securely store and retrieve user credentials.

// Example of securely storing user credentials in a session

session_start();

// Assuming $username and $password are obtained from a form submission
$username = $_POST['username'];
$password = $_POST['password'];

// Validate user credentials
if(validateCredentials($username, $password)) {
    $_SESSION['username'] = $username;
    // Redirect to a secure page
    header("Location: secure_page.php");
    exit();
} else {
    // Display error message
    echo "Invalid credentials";
}

// Function to validate user credentials
function validateCredentials($username, $password) {
    // Perform validation logic here
    return true; // Return true if credentials are valid, false otherwise
}