一个卡密生成器[前台源码]

八刀丁二
八刀丁二 This guy is lazy,Introduction has not been set

6 People liked this article · 8669 views

演示例子:http://jxidc.wang/?/card/
kami.png
拿dz的步骤来制作,以为很难,就动手试研究研究,。本来加在后台,生成卡密然后可以使用的。 就先拿来做前台来做实验了。 后台也打算访一个dz的卡密程序。 也不知道代码算简单还是算复杂。 新建文件夹 ``/app/ka/`` 文件 ``main.php`` 加入方法 头文件我就不写了 {{{ public function make_action(){ //提交表单页面 if(!$_POST['num']){ H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入数量'))); }else{ if(intval($_POST['num']) == 0){ H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入正确的数量'))); } } for ($i = 1; $i < $_POST['num'] + 1; $i++) { $ka = $this->model('ka')->make($_POST['card'],strlen($_POST['card'])); if(strlen($ka) != 0){ //生成成功 $ad .= "<br>".$i."-".$ka; }else{ //生成失败 $ad .="<br>".$i."-失败"; } } H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t($ad))); } }}} {{{ public function index_action(){ $this->crumb(AWS_APP::lang()->_t('在线卡密生成器'), '/ka/'); //加载模板,就自己写了吧,就提交表单 提交到 ka/make/ TPL::output('ka/index'); } }}} models 新建个 ``ka.php`` {{{ <?php if (!defined('IN_ANWSION')) { die; } class ka_class extends AWS_MODEL { var $rulekey = array("str"=>"\@", "num"=>"\#", "full"=>"\*"); var $sysrule = ''; var $rule = ''; var $rulemap_str = "ABCDEFGHIJKLMNPQRSTUVWXYZ"; var $rulemap_num = "123456789"; var $rulereturn = array(); public function make($rule = '', $num = 1) { $this->sysrule = "^[A-Z0-9".implode('|', $this->rulekey)."]+$"; for($i = 0; $i < $num ; $i++) { if($this->checkrule($rule)) { $this->rule = $rule; $card = $rule; foreach($this->rulereturn AS $key => $val) { $search = array(); foreach($val AS $skey => $sval) { $search[] = '/'.$this->rulekey[$key].'/'; } $card = preg_replace($search, $val, $card, 1); } } else { return 0; } } return $card; } public function checkrule($rule, $type = '0') { if(!preg_match("/(".$this->sysrule.")/i", $rule)){ return $rule; } if($type == 0) { foreach($this->rulekey AS $key => $val) { $match = array(); preg_match_all("/(".$val."){1}/i", $rule, $match); $number[$key] = count($match[0]); if($number[$key] > 0) { for($i = 0; $i < $number[$key]; $i++) { switch($key) { case 'str': $rand = mt_rand(0, (strlen($this->rulemap_str) - 1)); $this->rulereturn[$key][$i] = $this->rulemap_str[$rand]; break; case 'num': $rand = mt_rand(0, (strlen($this->rulemap_num) - 1)); $this->rulereturn[$key][$i] = $this->rulemap_num[$rand]; break; case 'full': $fullstr = $this->rulemap_str.$this->rulemap_num; $rand = mt_rand(0,(strlen($fullstr) - 1)); $this->rulereturn[$key][$i] = $fullstr[$rand]; break; } } } } } return true; } } ?> }}} 就这点代码 你说这多呢 还是少呢,你说要给我赞呢还是不给我赞呢?

Published on 2014-12-07 20:49

Disclaimers:

This document is written by 八刀丁二 Original published on WeCenter ,The copyright belongs to the author。

Log in,More exciting content waiting for you to find,Contribute wonderful answers,Participate in comment interaction

go Sign in! No accountgoregister

jat
2014-12-07 22:52
本来随机字符串的生成就很占 cpu,不限长度和数量肯定会出问题。
八刀丁二
2014-12-07 22:37
本来拿来学习,谁知变的惨不忍睹 哎
八刀丁二
2014-12-07 22:29
就拿来娱乐,还是不让玩好了!呵呵!
jat
2014-12-07 22:20
楼主网站已经打不开了,做下生成的限制,你这样做只用一个 IP 和一行命令就能搞你。
All Rights Reserved Powered BY WeCenter V4.1.0 © 2024 粤ICP备17116736号