如何用php实现电子邮件验证?
我使用php和laravel作为框架。我想让用户能够通过电子邮件激活他们的帐户 然而,我没有这方面的经验。我已经设置了一个表单,要求输入用户名、电子邮件和密码 这仍然是2013年实现这一目标的最佳方式吗 因此:如何用php实现电子邮件验证?,php,email,laravel,verification,Php,Email,Laravel,Verification,我使用php和laravel作为框架。我想让用户能够通过电子邮件激活他们的帐户 然而,我没有这方面的经验。我已经设置了一个表单,要求输入用户名、电子邮件和密码 这仍然是2013年实现这一目标的最佳方式吗 因此: 我需要为哈希密码创建一个数据库字段 在创建用户帐户时,为该字段创建一个随机密码,并通过电子邮件发送给他们 在url中提供带有密码和用户id的链接,链接到将电子邮件密码与db字段中的密码进行比较的页面 密码匹配时激活帐户(将active设置为1) 大致是这样的吗?在你的解释中,你忘记了最
大致是这样的吗?在你的解释中,你忘记了最重要的部分:随机散列。比较哈希,而不是密码。指南正确地解释了它 导游看上去很可靠
我会实现一个更好的随机密码生成器,
rand(10005000)
确实不是很好。您甚至可以设置要求输入密码的首次登录。在您的解释中,您忘记了最重要的部分:随机哈希。比较哈希,而不是密码。指南正确地解释了它
导游看上去很可靠
我会实现一个更好的随机密码生成器,
rand(10005000)
确实不是很好。您甚至可以设置要求输入密码的首次登录。警告:根据PHP手册,EREGI已被弃用
预赛是个不错的选择 警告:根据PHP手册,EREGI已被弃用
预赛是个不错的选择 电子邮件验证是一个简单的过程。有两种方法可以验证电子邮件,一种是向用户电子邮件地址发送代码,另一种是发送链接。这两种方法都是一样的。这是TalkersCode教程中的示例代码
// Table Scheme for Verify Table
CREATE TABLE `verify` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` text NOT NULL,
`password` text NOT NULL,
`code` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
// Table Scheme for verified_user table
CREATE TABLE `verified_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` text NOT NULL,
`password` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
if(isset($_POST['register']))
{
$email_id=$_POST['email'];
$pass=$_POST['password'];
$code=substr(md5(mt_rand()),0,15);
mysql_connect('localhost','root','');
mysql_select_db('sample');
$insert=mysql_query("insert into verify values('','$email','$pass','$code')");
$db_id=mysql_insert_id();
$message = "Your Activation Code is ".$code."";
$to=$email;
$subject="Activation Code For Talkerscode.com";
$from = 'your email';
$body='Your Activation Code is '.$code.' Please Click On This link <a href="verification.php">Verify.php?id='.$db_id.'&code='.$code.'</a>to activate your account.';
$headers = "From:".$from;
mail($to,$subject,$body,$headers);
echo "An Activation Code Is Sent To You Check You Emails";
}
if(isset($_GET['id']) && isset($_GET['code']))
{
$id=$_GET['id'];
$code=$_GET['id'];
mysql_connect('localhost','root','');
mysql_select_db('sample');
$select=mysql_query("select email,password from verify where id='$id' and code='$code'");
if(mysql_num_rows($select)==1)
{
while($row=mysql_fetch_array($select))
{
$email=$row['email'];
$password=$row['password'];
}
$insert_user=mysql_query("insert into verified_user values('','$email','$password')");
$delete=mysql_query("delete from verify where id='$id' and code='$code'");
}
}
//验证表的表方案
创建表“验证”(
`id`int(11)非空自动增量,
`电子邮件`文本不为空,
`密码`文本不为空,
`代码`文本不为空,
主键(`id`)
)引擎=MyISAM自动增量=6默认字符集=1
//已验证用户表的表方案
创建表“已验证用户”(
`id`int(11)非空自动增量,
`电子邮件`文本不为空,
`密码`文本不为空,
主键(`id`)
)引擎=MyISAM自动增量=6默认字符集=1
如果(isset($_POST['register']))
{
$email\u id=$\u POST['email'];
$pass=$_POST['password'];
$code=substr(md5(mt_rand()),0,15);
mysql_connect('localhost','root','');
mysql_select_db('sample');
$insert=mysql_查询(“插入到验证值('''$email','$pass','$code'));
$db_id=mysql_insert_id();
$message=“您的激活码是“$Code.”;
$to=$email;
$subject=“Talkerscode.com的激活码”;
$from='您的电子邮件';
$body='您的激活码是'$Code'。请单击此链接激活您的帐户。';
$headers=“From:”.$From;
邮件($to、$subject、$body、$headers);
回显“发送给您的激活码检查您的电子邮件”;
}
if(isset($\u GET['id'])和&isset($\u GET['code']))
{
$id=$_GET['id'];
$code=$_GET['id'];
mysql_connect('localhost','root','');
mysql_select_db('sample');
$select=mysql_查询(“从验证中选择电子邮件、密码,其中id='$id'和code='$code');
if(mysql_num_rows($select)==1)
{
while($row=mysql\u fetch\u array($select))
{
$email=$row['email'];
$password=$row['password'];
}
$insert_user=mysql_查询(“插入已验证的_用户值(“,$email”,“$password”)”);
$delete=mysql_查询(“从验证中删除,其中id='$id'和code='$code');
}
}
电子邮件验证是一个简单的过程。有两种方法可以验证电子邮件,一种是将代码发送到用户电子邮件地址,另一种是发送链接。这两种方法都有效。这是TalkersCode教程中的示例代码
// Table Scheme for Verify Table
CREATE TABLE `verify` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` text NOT NULL,
`password` text NOT NULL,
`code` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
// Table Scheme for verified_user table
CREATE TABLE `verified_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` text NOT NULL,
`password` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
if(isset($_POST['register']))
{
$email_id=$_POST['email'];
$pass=$_POST['password'];
$code=substr(md5(mt_rand()),0,15);
mysql_connect('localhost','root','');
mysql_select_db('sample');
$insert=mysql_query("insert into verify values('','$email','$pass','$code')");
$db_id=mysql_insert_id();
$message = "Your Activation Code is ".$code."";
$to=$email;
$subject="Activation Code For Talkerscode.com";
$from = 'your email';
$body='Your Activation Code is '.$code.' Please Click On This link <a href="verification.php">Verify.php?id='.$db_id.'&code='.$code.'</a>to activate your account.';
$headers = "From:".$from;
mail($to,$subject,$body,$headers);
echo "An Activation Code Is Sent To You Check You Emails";
}
if(isset($_GET['id']) && isset($_GET['code']))
{
$id=$_GET['id'];
$code=$_GET['id'];
mysql_connect('localhost','root','');
mysql_select_db('sample');
$select=mysql_query("select email,password from verify where id='$id' and code='$code'");
if(mysql_num_rows($select)==1)
{
while($row=mysql_fetch_array($select))
{
$email=$row['email'];
$password=$row['password'];
}
$insert_user=mysql_query("insert into verified_user values('','$email','$password')");
$delete=mysql_query("delete from verify where id='$id' and code='$code'");
}
}
//验证表的表方案
创建表“验证”(
`id`int(11)非空自动增量,
`电子邮件`文本不为空,
`密码`文本不为空,
`代码`文本不为空,
主键(`id`)
)引擎=MyISAM自动增量=6默认字符集=1
//已验证用户表的表方案
创建表“已验证用户”(
`id`int(11)非空自动增量,
`电子邮件`文本不为空,
`密码`文本不为空,
主键(`id`)
)引擎=MyISAM自动增量=6默认字符集=1
如果(isset($_POST['register']))
{
$email\u id=$\u POST['email'];
$pass=$_POST['password'];
$code=substr(md5(mt_rand()),0,15);
mysql_connect('localhost','root','');
mysql_select_db('sample');
$insert=mysql_查询(“插入到验证值('''$email','$pass','$code'));
$db_id=mysql_insert_id();
$message=“您的激活码是“$Code.”;
$to=$email;
$subject=“Talkerscode.com的激活码”;
$from='您的电子邮件';
$body='您的激活码是'$Code'。请单击此链接激活您的帐户。';
$headers=“From:”.$From;
邮件($to、$subject、$body、$headers);
回显“发送给您的激活码检查您的电子邮件”;
}
if(isset($\u GET['id'])和&isset($\u GET['code']))
{
$id=$_GET['id'];
$code=$_GET['id'];
mysql_connect('localhost','root','');
mysql_select_db('sample');
$select=mysql_查询(“从验证中选择电子邮件、密码,其中id='$id'和code='$code');
if(mysql_num_rows($select)==1)
{
while($row=mysql\u fetch\u array($select))
{
$email=$row['email'];
$password=$row['password'];
}
$insert_user=mysql_查询(“插入已验证的_用户值(“,$email”,“$password”)”);
$delete=mysql_查询(“从验证中删除,其中id='$id'和code='$code');
}
}
您知道您可以(也应该)使用filter\u var($email,filter\u VALIDATE\u email)
验证电子邮件。您知道您可以(也应该)使用filter\u var($email,filter\u VALIDATE\u email)
验证电子邮件。