如何在php中使用文本文件验证要注册的电子邮件地址?
我有一个简单的php登录程序,使用平面文件,而不是SQL 我有以下php文件来验证电子邮件地址和密码:如何在php中使用文本文件验证要注册的电子邮件地址?,php,authentication,email-validation,flat-file,Php,Authentication,Email Validation,Flat File,我有一个简单的php登录程序,使用平面文件,而不是SQL 我有以下php文件来验证电子邮件地址和密码: <?php //check that the email and password form are submitted and not empty. if(isset($_POST['register_button'])){//register button clicked if(isset($_POST['email']) &&
<?php
//check that the email and password form are submitted and not empty.
if(isset($_POST['register_button'])){//register button clicked
if(isset($_POST['email']) && !empty($_POST['email']) AND isset($_POST['password']) && !empty($_POST['password'])){
$email = trim(($_POST['email']));
$password_before_hash = trim(($_POST['password']));
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$msg = 'Please enter a valid email.';
}elseif(strlen($password_before_hash)<6){
$msg = 'Please enter a valid password.';
}else{
//open a text file with email|hashed password|hashed token to check if a user already exists.
$file1=fopen("validated.txt","r");
$finduser=false;
while(!feof($file1))
{
$line = fgets($file1);
$array = explode("|",$line);
if(trim($array[0]) == $email)
{
$finduser=true;
break;
}
}
fclose($file1);
if($finduser){//user found in validated list. User needs to login
$msg = 'Already registered. Please log in.';
} else {//user never registered.
//hash password and token
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$hash = md5(rand(100,50000));
//write data into the text file in the form: email|hashed password|hased token.
$file2=fopen("unvalidated.txt","a");
fwrite($file2,"$email|$password|$hash");
fwrite($file2,"\n");
fclose($file2);
$confirmed = false; //email not confirmed yet.
$to = $email;
$subject = 'validation';
$message = '
Validate by clicking here:
(mydirectory)/validate.php?email='.$email.'&hash='.$hash.'
';
mail($to,$subject,$message);
$msg = 'A validation email has sent to '. $email. '. Please follow the link.';
}
}
}else{
$msg = 'Please fill in the information.';
}
}
?>
那么,我如何检查用户是否单击了电子邮件中的链接?我想将他们的电子邮件、哈希密码和哈希令牌放入文本文件validated.txt
我该怎么办?请帮忙
Validate by clicking here:
(mydirectory)/validate.php?email=(myEmail)&hash=(randomHashValue)