1

私のサイトのユーザーに電子メールで送信されるアクティベーション リンクを期限切れにする簡単な方法が必要なだけです。現在、ユーザーが登録した日付がmysqlデータベースに保存されています。電子メールで送信されるリンクは次のようなものです: /activation.php?id=20

これが私の活性化です

    <? 
include_once "scripts/connect_to_mysql.php";
// Get the member id from the URL variable
$id = $_REQUEST['id'];
$id = ereg_replace("[^0-9]", "", $id); // filter everything but numbers for security
if (!$id) {
    echo "Missing Data to Run";
    exit(); 
}
// Update the database field named 'email_activated' to 1
$sql = mysql_query("UPDATE members SET emailactivated='1' WHERE id='$id'"); 
// Check the database to see if all is right now 
$sql_doublecheck = mysql_query("SELECT * FROM members WHERE id='$id' AND emailactivated='1'"); 
$doublecheck = mysql_num_rows($sql_doublecheck); 
if($doublecheck == 0){ 
// Print message to the browser saying we could not activate them
print "<br /><br /><div align=\"center\"><h3><strong><font color=red>Your account could not be activated!</font></strong><h3><br /></div>"; 
} elseif ($doublecheck > 0) {
// Print a success message to the browser cuz all is good 
// And supply the user with a link to your log in page, please alter that link line 
print "<br /><br /><h3><font color=\"#0066CC\"><strong>Your account has been activated!<br /><br />
</strong></font><a href=\"\">Click Here</a> to log in now.</h3>"; 
} 
?>
4

2 に答える 2

1

アクティベーション リンクを作成するときに、UNIX タイムスタンプをテーブルのレコードに保存します。

テーブルは次のようになります。

activation_links
id,link_hash,created_date,expiration_date,is_active,used_date

次に、アクティベーション時に有効期限を確認します

$key = $_GET['key'];
$sql = "SELECT COUNT(*) FROM activation_links WHERE link_hash = '$key' AND expiration_date <= ".time();

さらに、単純な数字のアクティベーション キーは使用したくありません。簡単に推測できない長いランダムな文字列を生成する必要があります。

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}

補足: MySQLi または PDO のいずれかを使用する必要があります。

元。

$db = new mysqli($host,$user,$pass,$dbname);
于 2013-02-06T03:22:14.767 に答える
0

データベースのメンバー テーブルにアクティベーション有効期限フィールドを配置する必要があります。そのようにして、メンバー レコードを作成するときに、たとえば 6 時間前の日付を挿入します。次に、リンクのクリックが処理されたら、アクティベーション日がまだ過ぎていないことを確認してください。

于 2013-02-06T03:23:40.273 に答える