My question is a bit tricky and couldn’t find the right manner in which to efficiently articulate it. I’m creating a unique activation string/link that combines a hashed username and time in PHP. However the exact time it gets the data to be sent to my database and the actual time it takes to send the email activation link to the user’s email account is different (maybe in milliseconds and sometimes seconds)-and this basically means I have different email activation Links from my database and email account. Let me show a code snippet:
$username = $_POST[‘username’];
$table = ‘users’;
$activate_field = ‘activate’;
$activate_code = md5($_POST[‘username’]) + time(); //provides unique code for activating
//few more lines of code then…
$query = $connect-> prepare(“INSERT INTO $table $acivate_field VALUES $activate_code”);
$query->execute();
//then the long code for sending the email with the activation code appended to the user’s email account
Is there a better way of generating unique strings every second maybe? Thanks for your time and appreciate any help and/or suggestions.P.S I'm using phpmailer for sending emails.
simply write generated code to variable and then variable to mail and database as I can see you already have code kept in variable before including it in your query
on a side note, you shouldn't access superglobals like $_POST directly as user input may be malicious and for the same reason you should use PDO prepared statements instead of string built queries