In the context of user registration, how can the combination of user ID and random number be used for verification and activation processes in PHP scripts?

To enhance security in user registration, the combination of user ID and a random number can be used for verification and activation processes. This can help prevent unauthorized access and ensure that the user registering is legitimate. By generating a random number and associating it with the user ID during registration, the user can be prompted to enter this combination to activate their account.

// Generate a random number
$randomNumber = mt_rand(1000, 9999);

// Save the random number in the database associated with the user ID
// This can be done during user registration process

// Send the random number to the user via email or SMS for verification

// During account activation, prompt the user to enter the random number along with their user ID
// Check if the entered random number matches the one saved in the database for the user ID
// If they match, activate the user's account