GVKun编程网logo

PHP邮箱验证示例教程(php邮箱验证示例教程视频)

53

对于想了解PHP邮箱验证示例教程的读者,本文将提供新的信息,我们将详细介绍php邮箱验证示例教程视频,并且为您提供关于discuz3.2x增加邮箱验证功能,discuz3.2x邮箱验证_PHP教程、j

对于想了解PHP邮箱验证示例教程的读者,本文将提供新的信息,我们将详细介绍php邮箱验证示例教程视频,并且为您提供关于discuz3.2x增加邮箱验证功能,discuz3.2x邮箱验证_PHP教程、js和php邮箱地址验证、js和php邮箱地址验证_PHP教程、js和php邮箱地址验证的实现_PHP教程的有价值信息。

本文目录一览:

PHP邮箱验证示例教程(php邮箱验证示例教程视频)

PHP邮箱验证示例教程(php邮箱验证示例教程视频)

在用户注册中最常见的安全验证之一就是邮箱验证。根据行业的一般做法,进行邮箱验证是避免潜在的安全隐患一种非常重要的做法,现在就让我们来讨论一下这些最佳实践,来看看如何在PHP中创建一个邮箱验证。

让我们先从一个注册表单开始:

<form method="post" action="http://mydomain.com/registration/">
 <fieldset>
 <label for="fname">First Name:</label>
 <input type="text" name="fname"required />
  </fieldset>

  <fieldset>
 <label for="lname">Last Name:</label>
 <input type="text" name="lname"required />
  </fieldset>

  <fieldset>
 <label for="email">Last name:</label>
 <input type="email" name="email"required />
  </fieldset>

  <fieldset>
 <label for="password">Password:</label>
 <input type="password" name="password"required />
  </fieldset>

  <fieldset>
 <label for="cpassword">Confirm Password:</label>
 <input type="password" name="cpassword"required />
  </fieldset>

  <fieldset>
    <button type="submit">Register</button>
  </fieldset>
</form> 

接下来是数据库的表结构:

CREATE TABLE IF NOT EXISTS `user` (
 `id` INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
 `fname` VARCHAR(255) ,
 `lname` VARCHAR(255) ,
 `email` VARCHAR(50) ,
 `password` VARCHAR(50) ,
 `is_active` INT(1) DEFAULT ''0'',
 `verify_token` VARCHAR(255) ,
 `created_at` TIMESTAMP,
 `updated_at` TIMESTAMP,
); 

一旦这个表单被提交了,我们就需要验证用户的输入并且创建一个新用户:

// Validation rules
$rules = array(
  ''fname'' => ''required|max:255'',
  ''lname'' => ''required|max:255'',
 ''email'' => ''required'',
 ''password'' => ''required|min:6|max:20'',
 ''cpassword'' => ''same:password''
);

$validator = Validator::make(Input::all(), $rules);

// If input not valid, go back to registration page
if($validator->fails()) {
 return Redirect::to(''registration'')->with(''error'', $validator->messages()->first())->withInput();
}

$user = new User();
$user->fname = Input::get(''fname'');
$user->lname = Input::get(''lname'');
$user->password = Input::get(''password'');

// You will generate the verification code here and save it to the database

// Save user to the database
if(!$user->save()) {
 // If unable to write to database for any reason, show the error
 return Redirect::to(''registration'')->with(''error'', ''Unable to write to database at this time. Please try again later.'')->withInput();
}

// User is created and saved to database
// Verification e-mail will be sent here

// Go back to registration page and show the success message
return Redirect::to(''registration'')->with(''success'', ''You have successfully created an account. The verification link has been sent to e-mail address you have provided. Please click on that link to activate your account.'');

 注册之后,用户的账户仍然是无效的直到用户的邮箱被验证。此功能确认用户是输入电子邮件地址的所有者,并有助于防止垃圾邮件以及未经授权的电子邮件使用和信息泄露。

 整个流程是非常简单的——当一个新用户被创建时,在注册过过程中,一封包含验证链接的邮件便会被发送到用户填写的邮箱地址中。在用户点击邮箱验证链接和确认邮箱地址之前,用户是不能进行登录和使用网站应用的。

 关于验证的链接有几件事情是需要注意的。验证的链接需要包含一个随机生成的token,这个token应该足够长并且只在一段时间段内是有效的,这样做的方法是为了防止网络攻击。同时,邮箱验证中也需要包含用户的唯一标识,这样就可以避免那些攻击多用户的潜在危险。

现在让我们来看看在实践中如何生成一个验证链接:

// We will generate a random 32 alphanumeric string
// It is almost impossible to brute-force this key space
$code = str_random(32);
$user->confirmation_code = $code; 

一旦这个验证被创建就把他存储到数据库中,发送给用户:

Mail::send(''emails.email-confirmation'', array(''code'' => $code, ''id'' => $user->id), function($message)
{
$message->from(''my@domain.com'', ''Mydomain.com'')->to($user->email, $user->fname . '' '' . $user->lname)->subject(''Mydomain.com: E-mail confirmation'');
}); 

邮箱验证的内容:

<!DOCTYPE html>
<html lang="en-US">
 <head>
 <meta charset="utf-8" />
 </head>

 <body>
 <p>
  Please confirm your e-mail address by clicking the following link:
  <a href="http://mydomain.com/verify?code=<?php echo $code; ?>&user=<?php echo $id; ?>"></a>
 </p>
 </body>
</html> 

现在让我们来验证一下它是否可行:

$user = User::where(''id'', ''='', Input::get(''user''))
  ->where(''is_active'', ''='', 0)
  ->where(''verify_token'', ''='', Input::get(''code''))
  ->where(''created_at'', ''>='', time() - (86400 * 2))
  ->first();

if($user) {
 $user->verify_token = null;
 $user->is_active = 1;

 if(!$user->save()) {
 // If unable to write to database for any reason, show the error
 return Redirect::to(''verify'')->with(''error'', ''Unable to connect to database at this time. Please try again later.'');
 }

 // Show the success message
 return Redirect::to(''verify'')->with(''success'', ''You account is now active. Thank you.'');
}

// Code not valid, show error message
return Redirect::to(''verify'')->with(''error'', ''Verification code not valid.''); 

结论:
上面展示的代码只是一个教程示例,并且没有通过足够的测试。在你的web应用中使用的时候请先测试一下。上面的代码是在Laravel框架中完成的,但是你可以很轻松的把它迁移到其他的PHP框架中。同时,验证链接的有效时间为48小时,之后就过期。引入一个工作队列就可以很好的及时处理那些已经过期的验证链接。

本文实PHPChina原创翻译,原文转载于http://www.phpchina.com/portal.php?mod=view&aid=39888,小编认为这篇文章很具有学习的价值,分享给大家,希望对大家的学习有所帮助。

您可能感兴趣的文章:
  • php实现验证邮箱格式的代码实例
  • PHP利用缓存处理用户注册时的邮箱验证,成功后用户数据存入数据库操作示例
  • 实例讲解PHP验证邮箱是否合格
  • PHP自带方法验证邮箱、URL、IP是否合法的函数
  • PHP自带方法验证邮箱是否存在
  • php邮箱地址正则表达式验证
  • php验证邮箱和ip地址最简单方法汇总
  • js和php邮箱地址验证的实现方法
  • php使用filter过滤器验证邮箱 ipv6地址 url验证
  • PHP+Ajax异步通讯实现用户名邮箱验证是否已注册( 2种方法实现)
  • 通过PHP实现用户注册后邮箱验证激活

discuz3.2x增加邮箱验证功能,discuz3.2x邮箱验证_PHP教程

discuz3.2x增加邮箱验证功能,discuz3.2x邮箱验证_PHP教程

discuz3.2x增加邮箱验证功能,discuz3.2x邮箱验证

为防止垃圾用户多次注册,为disczu增加邮箱验证功能。

大致分为二步: 1、申请邮箱,这里推荐使用腾讯免费企业邮箱:https://exmail.qq.com/portal/introducefree (对普通开发者来说50个名额已足够,只要买个域名就能申请到企业邮箱还是很划算的),如果有其他更好的,欢迎推荐下 2、在discuz中进行设置。     1的具体步骤: 进入注册页面注册成功,登录企业邮箱,首页显示,如图:   在成员与群组中增加一个部门,并且在部门下增加一个用户(用来收发邮件的用户):   在我的企业中进行设置管理员帐户 > 管理邮箱(必须是存在的,即在成员与群组中增加的那个用户)。   在域名商那里解析邮箱服务器,如图 ========================分割线=========================   2的具体步骤(在discuz中设置):   1、首先您需要有支持SMTP的邮箱,如果没有,参照1的步骤申请免费的企业邮箱。 2、进入论坛后台,点击“站长”> "邮件设置",填写您的管理员邮箱,点击最下方“提交”按钮:   3、在全局 > 注册与访问控制中勾选Email验证:     4、在Ucenter中进行设置,邮箱仍然使用admin@kindlemao.com即可。   5.测试是否能够发送成功:          



来自为知笔记(Wiz)



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1080764.htmlTechArticlediscuz3.2x增加邮箱验证功能,discuz3.2x邮箱验证 为防止垃圾用户多次注册,为disczu增加邮箱验证功能。 大致分为二步:1、申请邮箱,这里推...

js和php邮箱地址验证

js和php邮箱地址验证

邮箱地址验证有很多方法。在浏览器端,js邮箱验证可以通过正则表达式检测。

比如:源码

/^((([a-z]|\d|[!#\$%&''\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&''\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/ } View Code

调用很简单:

(isEmail(''youremail@yourdomain.com'')){ console.log(''This is email is valid''); } View Code

 

如果是进行服务器端验证。像php,则最简单的莫过于:

立即学习“PHP免费学习笔记(深入)”;

isEmail( filter_var(, } View Code

但是这个件事也可以整得复杂。

像这位。他建立起一整套的邮箱地址验证网站体系。估计很少人这么干。

说实话,不得不佩服。

js和php邮箱地址验证_PHP教程

js和php邮箱地址验证_PHP教程

邮箱地址验证有很多方法。在浏览器端,js邮箱验证可以通过正则表达式检测。

比如:源码

js和php邮箱地址验证_PHP教程 /^((([a-z]|\d|[!#\$%&''\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&''\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/ } View Code

调用很简单:

js和php邮箱地址验证_PHP教程 (isEmail(''youremail@yourdomain.com'')){ console.log(''This is email is valid''); } View Code

 

如果是进行服务器端验证。像php,则最简单的莫过于:

立即学习“PHP免费学习笔记(深入)”;

js和php邮箱地址验证_PHP教程 isEmail( filter_var(, } View Code

但是这个件事也可以整得复杂。

像这位。他建立起一整套的邮箱地址验证网站体系。估计很少人这么干。

说实话,不得不佩服。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/675208.htmlTechArticle邮箱地址验证有很多方法。在浏览器端,js邮箱验证可以通过正则表达式检测。 比如:源码 /^((([a-z]|\d|[!#\$%''\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF9...

js和php邮箱地址验证的实现_PHP教程

js和php邮箱地址验证的实现_PHP教程

关于PHP邮箱验证示例教程php邮箱验证示例教程视频的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于discuz3.2x增加邮箱验证功能,discuz3.2x邮箱验证_PHP教程、js和php邮箱地址验证、js和php邮箱地址验证_PHP教程、js和php邮箱地址验证的实现_PHP教程的相关信息,请在本站寻找。

本文标签: