<!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 [激活]字段,如果它与存储在数据库中的随机数匹配,则继续返回激活错误。 现在是我们如何做到这一点或有其他方式。另外我如何删除一段时间后未激活的账户。通过邮件激活用户账户
SHA1()做什么?以及cronjob做什么,在我如何实现它? – Kraken
SHA1()从字符串创建一个散列,请参阅http://php.net/manual/function.sha1.php。 使用cronjob脚本会自动在特定的时间段之间调用。也许你的提供者提供类似的东西,但也有很多其他的免费系统。 – ComFreek
是SHA和SHA1一样吗? – Kraken