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

帝国cms 设置验证码与检查验证码所执行的函数代码注释

0
<?php
//设置验证码
function ecmsSetShowKey($varname,$val,$ecms=0){
	global $public_r;
	$val=md5($val);
	$time=time();
	//验证码加密字符串
	$checkpass=md5(md5($val.'EmpireCMS'.$time).$public_r['keyrnd']);
	$key=$time.','.$checkpass.','.$val;
	esetcookie($varname,$key,0,$ecms);
}
//设置COOKIE
function esetcookie($var,$val,$life=0,$ecms=0){
	global $ecms_config;
	//参数$ecms为0时取前台cookie变量前缀,为1时取后台cookie变量前缀
	$varpre=empty($ecms)?$ecms_config['cks']['ckvarpre']:$ecms_config['cks']['ckadminvarpre'];
	return setcookie($varpre.$var,$val,$life,$ecms_config['cks']['ckpath'],$ecms_config['cks']['ckdomain']);
}
//返回cookie
function getcvar($var,$ecms=0){
	global $ecms_config;
	//参数$ecms为0时取前台cookie变量前缀,为1时取后台cookie变量前缀
	$tvar=empty($ecms)?$ecms_config['cks']['ckvarpre'].$var:$ecms_config['cks']['ckadminvarpre'].$var;
	return $_COOKIE[$tvar];
}
//检查验证码
function ecmsCheckShowKey($varname,$postval,$dopr,$ecms=0){
	global $public_r;
	$r=explode(',',getcvar($varname,$ecms));
	$cktime=$r[0];
	$pass=$r[1];
	$val=$r[2];
	$time=time();
	//$public_r['keytime']验证码过期时间,单位分钟
	if($cktime>$time||$time-$cktime>$public_r['keytime']*60){
		//OutKeytime 验证码已过期
		printerror('OutKeytime','',$dopr);
	}
	if(empty($postval)||md5($postval)<>$val){
		//FailKey 验证码不正确
		printerror('FailKey','',$dopr);
	}
	$checkpass=md5(md5(md5($postval).'EmpireCMS'.$cktime).$public_r['keyrnd']);
	if($checkpass<>$pass){
		printerror('FailKey','',$dopr);
	}
}
?>

建站咨询

咨询热线

微信交流

返回顶部