<?php
// create this link for use in 1 hour
$plain_key = $member_id.date('Y-m-d H');
$key = password_hash($plain_key, PASSWORD_DEFAULT);
$create_link = 'https://.....?k='.$key;
?>
<?php
// This section for verify link key
$key_for_verify = $member_id.date('Y-m-d H');
if( password_verify($key_for_verify,$_GET['k']) )
{
// TRUE
}
// FALSE
请引导我。如果你有一些想法。
或者你有一些例子。请帮忙,谢谢
最好在链接中包含时间戳,并使用HMAC-SHA512/HMAC-SHA256嵌入认证代码。然后检查时间戳是否被用户修改。
生成脚本
// create this link for use in 1 hour
$unix_ts = time();
//convert to string
$unix_ts = $unix_ts . '';
//compute signature
$sig = hash_hmac('sha256', $unix_ts, SERVER_SECRET);
$create_link = 'https://.....?t='.$unix_ts.'&sig='.$sig;
Chekcing脚本
//check signature
$unix_ts_req = $_GET['t'];
$sig = hash_hmac('sha256', $unix_ts_req, SERVER_SECRET);
//check if signature match
if($sig === $_GET['sig'])
{
$gap = time() - (int)$unix_ts_req;
if($gap < 3600)
{
//valid
}
else
{
//expired
}
}
else
{
// url tempered
}
以上代码作为示例。不是测试。