您发送给管理员的电子邮件必须包含如下链接:
http://www.example.org/admin/remove_account.php?id=123
123
注册的用户在哪里,并且remove_account.php
是单击链接时将加载的脚本。
在脚本中,您将拥有如下内容:
mysql_query("DELETE FROM table_name WHERE id=" . mysql_real_escape_string($_GET['id']));
警告
谨言慎行。上述链接应受以下一项保护:
- 用户和密码保护(使用 Apache 或 PHP)
- 签名保护(下例)
签名保护通过添加签名来防止篡改/伪造链接参数。像这样工作:
$secret = "some reasonably long string of random data";
$id = "123"; // like above, the user id
$sig = hash_hmac('sha1', $id, $secret);
$link = 'http://www.example.org/admin/remove_account.php?' . http_build_query(array(
'id' => $id,
'sig' => $sig,
));
要验证签名:
$secret = "some reasonably long string of random data";
if (isset($_GET['id'], $_GET['sig'])) {
$calc_sig = hash_hmac('sha1', $_GET['id'], $secret);
if ($calc_sig === $_GET['sig']) {
// your delete query here
}
}
请注意,尽管该链接可以防止有人试图访问您的管理脚本,但如果它落入坏人之手,您仍然会被搞砸。不要低估安全性:)