您当前的位置:首页 > CMS常见问题 > 帝国cms常见问题 >

帝国cms会员注册register()函数代码注释

0
<?php
function register($add){
	global $empire,$dbtbpre,$public_r,$ecms_config;
	//用户设置-前台设置-会员注册,0开启,1关闭
	if($public_r['register_ok'])
	{
		//抱歉, 由于系统维护, 暂时关闭会员注册功能。
		printerror('CloseRegister','',1);
		//@include ECMS_PATH."e/data/"."../data/language/gb/pub/q_message.php";
		//$error = $qmessage_r["CloseRegister"];
		//@include(ECMS_PATH."e/data/"."../message/index.php");
	}
	eCheckTimeCloseDo('reg');//验证时间段允许操作
	eCheckAccessDoIp('register');//验证IP
	//如果设置了会员注册地址, 则转向注册地址
	if(!empty($ecms_config['member']['registerurl']))
	{
		header('location:'.$ecms_config['member']['registerurl']);
		exit();
	}
	if(getcvar('mluserid'))
	{
		//您已登录, 不能注册帐号
		printerror('LoginToRegister','',1);
	}
	checkCanPostUrl();//验证来源
	//使用第三方注册, 密码取8位随机密码, 使用第三方账号头像
	$tobind=(int)$add['tobind'];
	if($tobind)
	{
		$add['password']=make_password(8);
		$add['repassword']=$add['password'];
	}
	$username=trim($add['username']);
	$password=trim($add['password']);
	$username=RepPostVar($username);
	$password=RepPostVar($password);
	$email=RepPostStr($add['email']);
	$truepassword=$password;
	if(!$username||!$password||!$email)
	{
		//用户名, 密码与邮箱不能为空
		printerror('EmptyMember','history.go(-1)',1);
	}
	//验证码
	$keyvname='checkregkey';
	if($public_r['regkey_ok'])
	{
		ecmsCheckShowKey($keyvname,$add['key'],1);
	}
	$user_groupid=eReturnMemberDefGroupid();
	$groupid=(int)$add['groupid'];
	$groupid=empty($groupid)?$user_groupid:$groupid;
	CheckMemberGroupCanReg($groupid);//验证会员组是否可注册
	$regip=egetip();
	$regipport=egetipport();
	$pr=$empire->fetch1("select min_userlen,max_userlen,min_passlen,max_passlen,regretime,regclosewords,regemailonly from {$dbtbpre}enewspublic limit 1");
	$userlen=strlen($username);
	if($userlen<$pr['min_userlen']||$userlen>$pr['max_userlen'])
	{
		//用户名长度有误
		printerror('FaiUserlen','',1);
	}
	$passlen=strlen($password);
	if($passlen<$pr['min_passlen']||$passlen>$pr['max_passlen'])
	{
		//密码位数不够或过长
		printerror('FailPasslen','',1);
	}
	if($add['repassword']!==$password)
	{
		//二次密码不一致
		printerror('NotRepassword','',1);
	}
	if(!chemail($email))
	{
		//您输入的邮箱有误
		printerror('EmailFail','',1);
	}
	if(!preg_match("/^[A-Za-z0-9_\x{4e00}-\x{9fa5}]+$/u",$username))
	{
		printerror("用户名只能由中文、英文、数字及下划线组成","",1);
	}
	eCheckIpRegTime($regip,$pr['regretime']);//同一IP注册间隔限制
	toCheckCloseWord($username,$pr['regclosewords'],'RegHaveCloseword');//用户名保留关键字
	$username=RepPostStr($username);
	//检查用户名是否已存在
	$num=$empire->gettotal("select count(*) as total from ".eReturnMemberTable()." where ".egetmf('username')."='$username' limit 1");
	if($num)
	{
		//此用户名已被注册, 请重填!
		printerror('ReUsername','',1);
	}
	//会员邮箱唯一性检查, 1开启, 0关闭
	if($pr['regemailonly'])
	{
		$num=$empire->gettotal("select count(*) as total from ".eReturnMemberTable()." where ".egetmf('email')."='$email' limit 1");
		if($num)
		{
			//此邮箱已被注册
			printerror('ReEmailFail','',1);
		}
	}
	$lasttime=time();//注册时间
	$registertime=eReturnAddMemberRegtime();//返回当前注册时间
	$rnd=make_password(20);//产生20位随机数, 作为随机认证码
	$userkey=eReturnMemberUserKey();//产生12位随机数

	$salt=eReturnMemberSalt();
	$password=eDoMemberPw($password,$salt);
	//根据会员组ID返回是否需要审核
	//这里如果注册需要审核, 则返回0, 否则返回1
	$checked=ReturnGroupChecked($groupid);

	//会员注册审核方式, 0无, 1邮件激活
	//这里的意思是: 如果该会员组的会员需要审核, 则$checked的值为0(以下条件不通过), 如果该会员组的会员不需要审核, 则$checked的值为1。 
	if($checked&&$public_r['regacttype']==1)
	{
		$checked=0;
	}
	//验证附加表必填项
	$mr['add_filepass']=ReturnTranFilepass();
	//该会员组使用的信息使用表单id
	$fid=GetMemberFormId($groupid);
	$member_r=ReturnDoMemberF($fid,$add,$mr,0,$username);



}



//验证注册时间
function eCheckIpRegTime($ip,$time){
	global $empire,$dbtbpre;
	if(empty($time))
	{
		return "";
	}
	//查询会员副表是否存在该IP的记录, 如果不存在则返回空字符串
	$uaddr=$empire->fetch1("select userid from {$dbtbpre}enewsmemberadd where regip='$ip' order by userid desc limit 1");
	if(empty($uaddr['userid']))
	{
		return "";
	}
	//根据IP在会员副表里返回的userid来查询该userid在会员主表里的记录, 如果不存在则返回空字符串
	$ur=$empire->fetch1("select ".eReturnSelectMemberF('userid,registertime')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$uaddr[userid]' limit 1");
	if(empty($ur['userid']))
	{
		return "";
	}
	$registertime=eReturnMemberIntRegtime($ur['registertime']);
	if(time()-$registertime<=$time*3600)
	{
		//同一IP不能重复注册
		printerror('RegisterReIpError','',1);
	}
}
//返回注册时间(int)
function eReturnMemberIntRegtime($regtime){
	global $ecms_config;
	//注册时间保存格式,0为正常时间,1为数值型
	return empty($ecms_config['member']['regtimetype'])?to_time($regtime):$regtime;
}
//时间转换函数
function to_time($datetime){
	if(strlen($datetime)==10)
	{
		$datetime.=" 00:00:00";
	}
	$r=explode(" ",$datetime);
	$t=explode("-",$r[0]);
	$k=explode(":",$r[1]);
	$dbtime=@mktime($k[0],$k[1],$k[2],$t[1],$t[2],$t[0]);
	return $dbtime;
}
//验证包含字符
function toCheckCloseWord($word,$closestr,$mess){
	if($closestr&&$closestr!='|')
	{
		$checkr=explode('|',$closestr);
		$ckcount=count($checkr);
		for($i=0;$i<$ckcount;$i++)
		{
			if($checkr[$i])
			{
				if(stristr($checkr[$i],'##'))//多字
				{
					$morer=explode('##',$checkr[$i]);
					if(stristr($word,$morer[0])&&stristr($word,$morer[1]))
					{
						printerror($mess,"history.go(-1)",1);
					}
				}
				else
				{
					if(stristr($word,$checkr[$i]))
					{
						printerror($mess,"history.go(-1)",1);
					}
				}
			}
		}
	}
}
//返回当前注册时间
function eReturnAddMemberRegtime(){
	global $ecms_config;
	//注册时间保存格式, 0为正常时间, 1为数值型
	return empty($ecms_config['member']['regtimetype'])?date('Y-m-d H:i:s'):time();
}
//返回UserKey
function eReturnMemberUserKey(){
	global $ecms_config;
	return make_password(12);
}
//返回SALT
function eReturnMemberSalt(){
	global $ecms_config;
	//SALT随机码字符数
	return make_password($ecms_config['member']['saltnum']);
}
//密码
function eDoMemberPw($password,$salt){
	global $ecms_config;
	if($ecms_config['member']['pwtype']==0)//单重md5
	{
		$pw=md5($password);
	}
	elseif($ecms_config['member']['pwtype']==1)//明码
	{
		$pw=$password;
	}
	elseif($ecms_config['member']['pwtype']==3)//16位md5
	{
		$pw=substr(md5($password),8,16);
	}
	else//双重md5
	{
		$pw=md5(md5($password).$salt);
	}
	return $pw;
}
//返回是否审核
function ReturnGroupChecked($groupid){
	global $level_r;
	if($level_r[$groupid]['regchecked']==1){
		$checked=0;
	}else{
		$checked=1;
	}
	//注册是否需要审核, 1是, 0否
	//如果注册需要审核, 则返回0, 否则返回1
	return $checked;
}
//返回filepass
function ReturnTranFilepass(){
	$filepass=time();
	return $filepass;
}
//取得表单id
function GetMemberFormId($groupid){
	global $empire,$dbtbpre;
	$groupid=(int)$groupid;
	$r=$empire->fetch1("select formid from {$dbtbpre}enewsmembergroup where groupid='$groupid'");
	return $r['formid'];
}
//返回会员字段
function ReturnDoMemberF($fid,$add,$mr,$ecms=0,$username='',$admin=0){
	global $empire,$dbtbpre,$ecms_config,$public_r;
	//openmembertranimg 文件设置-会员表单附件设置, 开启上传图片, 1为开启
	//memberimgsize 最大图片5120KB=5M
	//memberimgtype 图片扩展名.gif|.jpg|.png|.jpeg|.bmp
	//openmembertranfile 开启上传附件, 1为开启
	//memberfilesize 最大附件500KB
	//memberfiletype 附件扩展名.zip|.rar
	$pr=$empire->fetch1("select openmembertranimg,memberimgsize,memberimgtype,openmembertranfile,memberfilesize,memberfiletype from {$dbtbpre}enewspublic limit 1");
	//fid 表单ID
	//enter text 录入项
	//mustenter text 必填项
	//filef varchar(255) 附件字段集合
	//imgf varchar(255) 图片字段集合
	//canaddf text 可增加项
	//caneditf text 可修改项
	//checkboxf text 复选字段集合
	$formr=$empire->fetch1("select fid,enter,mustenter,filef,imgf,canaddf,caneditf,checkboxf from {$dbtbpre}enewsmemberform where fid='$fid'");
	//检测必填字段
	$mustr=explode(",",$formr['mustenter']);
	$mustcount=count($mustr);
	for($i=1;$i<$mustcount-1;$i++)
	{
		$mf=$mustr[$i];
		//附件或者图片
		if(strstr($formr['filef'],",".$mf.",")||strstr($formr['imgf'],",".$mf.","))
		{
			$mfilef=$mf."file";
			//上传文件
			if($_FILES[$mfilef]['name'])//用户系统中的文件名称
			{
				if(strstr($formr['imgf'],",".$mf.",")){
					//是否开启上传图片
					if(!$pr["openmembertranimg"]){
						printerror("CloseQTranPic","",1);
					}
				}else{
					//是否开启上传附件
					if(!$pr["openmembertranfile"]){
						printerror("CloseQTranFile","",1);
					}
				}
			}elseif(!trim($add[$mf])&&!$mr[$mf]){
				printerror("EmptyQMustF","",1);
			}
		}else{
			//例如 ReturnMCheckboxAddF($add["hobby"], "hobby", ",hobby,")
			$chmustval=ReturnMCheckboxAddF($add[$mf],$mf,$formr['checkboxf']);
			if(!trim($chmustval)){
				printerror("EmptyQMustF","",1);
			}
		}
	}
	//字段处理
	$dh="";
	$tranf="";
	$record="<!--record-->";
	$field="<!--field--->";

# 0 爱好<!--field--->hobby<!--record-->
# 1 真实姓名<!--field--->truename<!--record-->
# 2 联系电话<!--field--->mycall<!--record-->
# 3 手机<!--field--->phone<!--record-->
# 4 QQ号码<!--field--->oicq<!--record-->
# 5 MSN<!--field--->msn<!--record-->
# 6 网站地址<!--field--->homepage<!--record-->
# 7 会员头像<!--field--->userpic<!--record-->
# 8 联系地址<!--field--->address<!--record-->
# 9 邮编<!--field--->zip<!--record-->
# 10 简介<!--field--->saytext<!--record-->
# 11

	$fr=explode($record,$formr['enter']);
	$count=count($fr);
	for($i=0;$i<$count-1;$i++)
	{
		$fr1=explode($field,$fr[$i]);
		$f=$fr1[1];
		//参数 $ecms $admin 默认等于0
		if($admin==0 && (($ecms==0&&!strstr($formr['canaddf'],','.$f.','))||($ecms==1&&!strstr($formr['caneditf'],','.$f.',')))){
			continue;
		}
		//附件
		$add[$f]=str_replace('[!#@-','ecms',$add[$f]);
		if(strstr($formr['filef'],",".$f.",")||strstr($formr['imgf'],",".$f.","))
		{
			//上传附件
			$filetf=$f."file";
			if($_FILES[$filetf]['name'])
			{
				$filetype=GetFiletype($_FILES[$filetf]['name']);//取得文件类型
				if(CheckSaveTranFiletype($filetype)){
					printerror("NotQTranFiletype","",1);
				}
				//图片
				if(strstr($formr['imgf'],",".$f.","))
				{
					//是否开启上传图片
					if(!$pr['openmembertranimg']){
						printerror("CloseQTranPic","",1);
					}
					if(!strstr($pr['memberimgtype'],"|".$filetype."|")){
						printerror("NotQTranFiletype","",1);
					}
					if($_FILES[$filetf]['size']>$pr['memberimgsize']*1024){
						printerror("TooBigQTranFile","",1);
					}
					if(!strstr($ecms_config['sets']['tranpicturetype'],','.$filetype.',')){
						printerror("NotQTranFiletype","",1);
					}
				//附件
				}else{
					//是否开启上传附件
					if(!$pr['openmembertranfile']){
						printerror("CloseQTranFile","",1);
					}
					if(!strstr($pr['memberfiletype'],"|".$filetype."|")){
						printerror("NotQTranFiletype","",1);
					}
					if($_FILES[$filetf]['size']>$pr['memberfilesize']*1024){
						printerror("TooBigQTranFile","",1);
					}
				}
				$tranf.=$dh.$f;
				$dh=",";
				$fval="[!#@-".$f."-@!]";
			}
			else
			{
				//modmemberedittran 会员附件字段支持填写 1是 0否
				if($public_r['modmemberedittran']==1)
				{
					$fval=$add[$f];
					if($ecms==1&&$mr[$f]&&!trim($fval))
					{
						$fval=$mr[$f];
					}
				}
				else
				{
					$fval='';
					if($ecms==1)
					{
						$fval=$mr[$f];
					}
				}
			}
		}
		else
		{
			$add[$f]=ReturnMCheckboxAddF($add[$f],$f,$formr['checkboxf']);
			$fval=$add[$f];
		}
		$fval=DoMemberFValue($fval);
		$fval=RepPostStr2($fval);
		$fval=addslashes($fval);
		//添加
		if($ecms==0)
		{
			$ret_r[0].=",`".$f."`";
			$ret_r[1].=",'".$fval."'";
		//编辑
		}else{
			$ret_r[0].=",`".$f."`='".$fval."'";
		}
	}






	//上传附件
	if($tranf)
	{
		$infoid=0;
		$filepass=0;
		$classid=0;
		$filepass=(int)$mr['add_filepass'];
		$tranr=explode(",",$tranf);
		$count=count($tranr);
		for($i=0;$i<$count;$i++)
		{
			$tf=$tranr[$i];
			$tffile=$tf."file";
			$tfr=DoTranFile($_FILES[$tffile]['tmp_name'],$_FILES[$tffile]['name'],$_FILES[$tffile]['type'],$_FILES[$tffile]['size'],$classid);
			if($tfr['tran'])
			{
				if(strstr($formr['imgf'],",".$tf.","))//图片
				{
					$type=1;
				}
				else//附件
				{
					$type=0;
				}
				//写入数据库
				$filesize=(int)$_FILES[$tffile]['size'];
				eInsertFileTable($tfr[filename],$filesize,$tfr[filepath],'[EditInfo]'.$username,$classid,'Member['.$tf.']',$type,$filepass,$filepass,$public_r[fpath],0,6,0);
				//删除旧文件
				if($ecms==1&&$mr[$tf])
				{
					DelYMemberTranFile($mr[$tf],$tf,$username);
				}
				$repfval=$tfr['url'];
			}
			else
			{
				$repfval=$mr[$tf];
			}
			if($ecms==0)//添加
			{
				$ret_r[1]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[1]);
			}
			else//编辑
			{
				$ret_r[0]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[0]);
			}
		}
	}
	return $ret_r;
}
?>

建站咨询

咨询热线

微信交流

返回顶部