0

I wish to create a log in system where every time a user logs in, this activity is logged in another table. How is this possible?

I am using PHP and MySQL, I have an ok knowledge of the two and currently have a system that I have designed using various tutorials.

It is very simple as that is all I require at the moment however I may look to streamline the code at a later date by making it object oriented however this is above my skill level at this time.

The user registers with their name, username, password and email. The user is then emailed their log in details - what I would like is for the user to have to click a link in within the email lot activate their account.*1

Once the user has activated their account the user logs in with a username and password - I would like their 'activity' to be stored, i.e the date/time that they log in.*2

*1: Currently, when the user registers, they receive an email with their log in details, I would like the email to contain a link so that they can 'activate' their account. How can I implement this. I know that I should store a unique code in the database but I do not know how to send that information to the user and to check it against the database.

*2: I would like the date and time stored in a table when the user logs in, so that their 'activity history' can be checked. How do I go about this. I know that I need to create a new table called something like 'log' which merely stores the username and date, but I do not know how to populate it when the user logs in.

If anyone can help that's be more than appreciated.

4

2 に答える 2

4

ここでは、ログインシステムの作成方法について前に説明しました。この投稿を確認してください。これはあなたを助けるかもしれません。

オープンソースのリッチHTMLエディター

アクティベーションのためのメールの送信について。上記で説明したコードに以下を追加する必要があります。

activation_stringテーブルusersに列を追加します。これで、ファイナルテーブルは次のようになります。

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  `activation_string` varchar(50) NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
);

このactivation_string列には、ユーザーの電子メールに送信されるアクティベーション文字列が保持されます。ユーザーがそれをクリックすると、ユーザーアカウントがアクティブ化されるようにします。ここでアクティベーション文字列を生成するには、以下の関数を使用します。

function generateActivationString() {
    $randomSalt = '*&(*(JHjhkjnkjn9898';
    $uniqId = uniqid(mt_rand(), true);
    return md5($randomSalt.$uniqId);
}

次に、登録フォームでユーザーを表します。フォームを送信するときは、次のことを行う必要があります。

$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string(sha1($_POST['password']));
$activationString = generateActivationString();
mysql_query("INSERT INTO users (email,password, activation_string) VALUES('$name','$password','$activationString')");

同時に、URIとして表されるアクティベーション文字列を使用してユーザーに電子メールを送信します。それを行う方法については、以下のコードを確認してください。

$email = $_POST['email'];
$message = 'http://mysite.com/activate.php?confirm='.$activationString;
$to = $email;
$subject = 'User Account Confirmation';
$body =     $message . PHP_EOL;
mail($to, $subject, $body);

次に、別のスクリプトを記述して文字列を検証し、アクティブ化文字列が検証された場合はステータスの値を1に更新します。

これがあなたが何をすべきかを理解するのに役立つことを願っています。

于 2011-08-27T11:08:34.723 に答える
1

ユーザー アクティビティ (最終ログイン日など) をログに記録したい場合は、usersテーブルに別のフィールドを作成して、last_loginまたはlast_activity(好きな方) のような名前を付けることができます。そして、ログイン時に、入力したパスワードを確認した後、フィールドを現在の日付で更新します。

if ($password === $storedpassword)
{

  // Password correct.
  $currentDate = date('Y-m-d g:i:s a');
  mysql_query('UPDATE `users` SET `last_login` = "' . $currentDate . '"');

}
于 2011-08-27T12:30:11.000 に答える