2011-07-20 12 views
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<body> 
<?php 

require_once('database_detail.php'); 
if(isset($_POST['submit'])) 
{ 
$dbc=mysqli_connect(cname,chost,cpwd,cdb); 
$username=mysqli_real_escape_string($dbc,trim($_POST['username'])); 
$password=mysqli_real_escape_string($dbc,trim($_POST['password'])); 
$confirm=mysqli_real_escape_string($dbc,trim($_POST['confirm'])); 
$email=mysqli_real_escape_string($dbc,trim($_POST['email'])); 
$phone=mysqli_real_escape_string($dbc,trim($_POST['phone'])); 
    if(!empty($username) && !empty($password) && !empty($confirm) && !empty($email) &&  !empty($phone)) 
    { 
      if($password==$confirm) 
      { 
       $query="select * from user where  user_username='$username'"; 
       $data=mysqli_query($dbc,$query); 
       if(mysqli_num_rows($data)== 0) 
       { 
        $random=rand(1000,10000); 
        $query="insert into  user(user_username,user_password,user_email,user_phone,date,random)". 
         "values('$username',SHA('$password'),'$email','$phone',now(),'$random')"; 
        mysqli_query($dbc,$query); 
        $message="Account created successfully, kindly  visit the following link to activate your account"."\n"."localhost/login? activation=".$random; 
        $to=$email; 
        $subject="Account Activation"; 
         mail($to,$subject,$message,'From:'.'[email protected]'); 
        echo 'Account created successfully. kindly visit  your email addres and activate your account.'; 
       exit(); 

       } 
       else 
      { 
       echo 'same username exists'; 
       $username=""; 
       } 
      } 
      else echo 'Enter the same password in both'; 
    } 
    else echo 'Enter all the fields'; 
} 
?> 

<fieldset> 
<legend>signup</legend> 
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" > 
Username:<input type="text" id="username" name="username" /> 
Password:<input type="password" name="password" id="password" /> 
Email<input type="text" name="email" id="email" /> 
Contact number<input type="text" name="phone" id="phone" /> 
Confirm Password:<input type="password" name="confirm" id="confirm" /> 
</fieldset> 
<input type="submit" name="submit" value="Sign up" /> 
</form> 
</body> 
</html> 

これは、アクティベーションメールで一意のユーザ名のパスワードでサインアップしたユーザに郵送するためのものです。今私は乱数を生成する、私はユーザーのデータベースにその特定の乱数を格納し、また、0または1(活性化されていないか、または活性化されている)であるデータベースに活性化フィールドがあります。ユーザがログインすると、活動化フィールドをチェックし、そうであれば処理を続行し、そうでなければURLの$ _GET [activation]フィールドをチェックし、データベースに格納されている乱数と一致する場合はelse起動エラーを返す。 これは私たちがやっているやり方です。また、一定期間後にアクティブになっていないアカウントを削除するにはどうすればいいですか?メールを送信してユーザのアカウントを有効にする

答えて

2

私はrand()でアクティベーションキーを作成しません。 2人で同じ番号が得られる可能性があります。

私は常にユーザー名と現在の時刻でSHA1()を使用します。不活性化されたアカウントの自動削除のために


あなたは自動的に登録時刻と現在時刻との差をチェックするcronジョブを作成することができます。

+0

SHA1()は何ですか?また、どのように私はそれを実装するのですか、cronjobは何をしますか? – Kraken

+0

SHA1()は文字列からハッシュを作成します.http://php.net/manual/function.sha1.phpを参照してください。 クローンを使用すると、スクリプトは特定の期間に自動的に呼び出されます。たぶんあなたのプロバイダは、そのようなものを提供するかもしれませんが、多くの他のフリーシステムもあります。 – ComFreek

+0

はSHAとSHA1は同じですか? – Kraken

0

チェック:How to Generate secure activation link

user603003は右、クーロン、スケジュール運転を行うために使用される単純なLinuxのプログラムは、私が個人的にセッションファイルを削除するためにそれを使用すると述べました。 cronの使い方

Here is the format of a cron job file: 

[min] [hour] [day of month] [month] [day of week] [program to be run] 

where each field is defined as 
[min] Minutes that program should be executed on. 0-59. Do not set as * or the program will be run once a minute. 
[hour] Hour that program should be executed on. 0-23. * for every hour. 
[day of month] Day of the month that process should be executed on. 1-31. * for every day. 
[month] Month that program whould be executed on. 1-12 * for every month. 
[day of week] Day of the week. 0-6 where Sunday = 0, Monday = 1, ...., Saturday = 6. * for every day of the week. 
[program] Program to be executed. Include full path information. 

Here are some examples: 

0,15,30,45 * * * * /usr/bin/foo 

Will run /usr/bin/foo every 15 minutes on every hour, day-of-month, month, and day-of-week. In other words, it will run every 15 minutes for as long as the machine it running. 
関連する問題