PHPIN.NET

 找回密码
 立即注册
查看: 4778|回复: 0

[技巧手记] 帝国cms注册时用户名和email的即时检测函数

[复制链接]

469

主题

31

回帖

5507

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5507
发表于 2015-2-10 10:25:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
帝国cms注册时用户名和email的即时检测函数


  1. /*ajax处理函数*/
  2. function CheckUsername($param,$name){//Username
  3.         global $empire,$public_r,$dbtbpre;
  4.         $length=mb_strlen($param);
  5.         if($length < 4 || $length > 20){
  6.                 $tips='{"info":"Error!","status":"n"}';
  7.         }else{
  8.                 $r=$empire->fetch1("select count(*) as total from {$dbtbpre}enewsmember where $name='$param' limit 1");
  9.         if($r['total']){
  10.                         $tips='{"info":"用户名已存在,请选择其他用户名!","status":"n"}';
  11.                 }else{
  12.                         $tips='{"info":"恭喜您,此用户名可使用!","status":"y"}';
  13.                 }
  14.         }
  15.         return $tips;
  16. }
  17. function CheckEmail($param,$name){//Email
  18.         global $empire,$public_r,$dbtbpre;
  19.         $exp='/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i';
  20.         if(preg_match($exp,$param)){
  21.                 $r=$empire->fetch1("select count(*) as total from {$dbtbpre}enewsmember where $name='$param' limit 1");
  22.                 if($r['total']){
  23.                         $tips='{"info":"邮箱已被使用,请选择其他邮箱!","status":"n"}';
  24.                 }else{
  25.                         $tips='{"info":"恭喜您,此邮箱可使用!","status":"y"}';
  26.                 }
  27.         }else{
  28.                 $tips='{"info":"邮箱格式不正确!","status":"n"}';
  29.         }
  30.         return $tips;
  31. }
复制代码


以上只是个人经验分享,具体使用请参考自身项目。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|PHPIN.NET ( 冀ICP备12000898号-14 )|网站地图

GMT+8, 2024-4-20 05:49

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表