Answer the question
In order to leave comments, you need to log in
Is it possible to confirm the letter within two hours?
The bottom line is, the client is sent a letter and he needs to confirm it.
Чтобы подтвердить <a href="http://med.maz.by/site/confim?secretkey=<?=$secretkey;?>">нажмите здесь.</a>
$secretkey = Yii::$app->security->hashData($id, '8036121');
Answer the question
In order to leave comments, you need to log in
$token = Yii::$app->security->hashData(time().'|'.$id, 'secret-key');
$data = Yii::$app->security->validateData($token, 'secret-key');
try {
list($time, $id) = explode('|', $data);
$model = MyModel::findOne($id);
if (null === $model || time() > $time + 2 * 3600) {
throw new Exception();
}
}
catch (Exception $e) {
echo 'Token invalid';
}
1. Generate a secretKey and save it along with the date and time of generation
2. Send an email with a link to the client
3. When the client follows the link, check if the specified secretKey exists and if its date has expired.
4. Depending on the result of the check, display the desired page
I don't see the point in messing with the database. It is necessary to form a link with id, time and token for verification
$secret = 'some string';
$i = $model->id;
$time = strtotime('now');
$token = md5($i.$time.$secret);
$url = Url::toRoute([
'controller/action',
'i' => $id,
't' => $time,
's' => $token,
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question