thinkphp实现卡号卡密批量导入数据库方法
时间:2023年12月24日
/来源:网络
/编辑:佚名
thinkphp实现卡号卡密批量导入数据库方法后端代码
点击复制代码 PHP
public function adddao()
{
if (IS_POST) {
$filename = input('post.filename/s');
!empty($filename) && @unlink($filename);
$split_type = input('split_type/s', ' ');
$content = input('content/s', '');
$check_card = input('check_card/d', 0);
$arr = explode(PHP_EOL, trim($content));
$count = count($arr);
//去除数组两端的空白字符
$arr = array_map(function ($v) {
return trim(str_replace(chr(194) . chr(160),' ', $v));
}, $arr);
if ($check_card == 1) {
$arr = array_values(array_unique($arr));
}
if ($split_type == '0') { //自动识别
if (strpos($arr[0], " ") !== false) {
$split_type = " ";
} elseif (strpos($arr[0], ",") !== false) {
$split_type = ",";
} elseif (strpos($arr[0], "|") !== false) {
$split_type = "|";
} elseif (strpos($arr[0], "----") !== false) {
$split_type = "----";
} else {
$split_type = "";
}
}
$cards = [];
foreach ($arr as $v) {
if (!empty($split_type)) {
$card = explode($split_type, $v);
} else {
$card = [$v, ''];
}
if (isset($card[0])) {
$card[0] = trim(html_entity_decode($card[0]), chr(0xc2) . chr(0xa0));
} else {
continue;
}
if ($card[0] === '') {
continue;
}
if (strlen($card[0]) > 255) {
continue;
}
// if(validateURL($card[0])) {//禁止url
// $this->error('虚拟卡内容不能包含链接');
// }
$number = $card[0];
if (isset($card[1])) {
$card[1] = trim(html_entity_decode($card[1]), chr(0xc2) . chr(0xa0));
} else {
continue;
}
if ($card[1] !== '') {
if (strlen($card[1]) > 255) {
continue;
}
$secret = $card[1];
} else {
$secret = '';
}
// 检查重复
if ($check_card == 1) {
$isExist =$this->db->where(['number' => $number, 'secret'=>$secret])->find();
if ($isExist) {
continue;
}
}
$cards[] = [
'number' => $number,
'secret' => $secret,
'status' => 1, // 未使用
];
}
if(!empty($cards))
{
$res = $this->db->insertAll($cards);
if (false !== $res) {
$this->success("操作成功,有效新增".$res.'条数据', weapp_url('Iplist/Iplist/index'));
}else{
$this->error("操作失败");
}
}else{
$this->success('虚拟卡内容格式不正确, 或卡密已存在', weapp_url('Iplist/Iplist/index'));
}
exit;
}
$this->assign('info', $info);
return $this->fetch('adddao');
}
thinkphp实现卡号卡密批量导入数据库方法教程-78模板网博客 - 一个分享技术、记录生活的个人技术博客
前端代码:
点击复制代码 Markup
<form class="form-horizontal" id="post_form" action="{:url('Ka/Ka/adddao')}" method="post">
<div class="ncap-form-default">
<dl class="row">
<dt class="tit">
<label>导入格式</label>
</dt>
<dd class="opt">
<div class="onoff">
<select name="split_type" class="form-control">
<option value="0">自动识别</option>
<option value=" ">用“ ”分隔</option>
<option value=",">用“,”分隔</option>
<option value="|">用“|”分隔</option>
<option value="----">用“----”分隔</option>
<option value="">不分隔</option>
</select>
</div>
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label>检查重复卡</label>
</dt>
<dd class="opt">
<div class="onoff">
<label for="target1" class="cb-enable selected">是</label>
<label for="target0" class="cb-disable ">否</label>
<input id="target1" name="check_card" value="1" type="radio" checked="checked">
<input id="target0" name="check_card" value="0" type="radio">
</div>
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label for="title"><em>*</em>ip+密码列表</label>
</dt>
<dd class="opt">
<textarea style="width:500px; height:350px;" name="content" id="content" placeholder="如:AAAAAAAAAAA BBBBBBBBBBBB"></textarea>
<span class="err"></span>
<p class="">提示:不允许为空,一行代表一个!</p>
</dd>
</dl>
<div class="bot" style="margin-top:10px;">
<input type="hidden" name="filename" id="filename" value="">
<a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
</div>
</div>
</form>
</div>
<script type="text/javascript">
// 判断输入框是否为空
function checkForm(){
if ($("#content").val() == '') {
showErrorMsg('ip+密码列表不能为空!');
$('#content').focus();
return false;
}
layer_loading('正在处理');
$('#post_form').submit();
}
</script>
点击复制代码 PHP
public function adddao()
{
if (IS_POST) {
$filename = input('post.filename/s');
!empty($filename) && @unlink($filename);
$split_type = input('split_type/s', ' ');
$content = input('content/s', '');
$check_card = input('check_card/d', 0);
$arr = explode(PHP_EOL, trim($content));
$count = count($arr);
//去除数组两端的空白字符
$arr = array_map(function ($v) {
return trim(str_replace(chr(194) . chr(160),' ', $v));
}, $arr);
if ($check_card == 1) {
$arr = array_values(array_unique($arr));
}
if ($split_type == '0') { //自动识别
if (strpos($arr[0], " ") !== false) {
$split_type = " ";
} elseif (strpos($arr[0], ",") !== false) {
$split_type = ",";
} elseif (strpos($arr[0], "|") !== false) {
$split_type = "|";
} elseif (strpos($arr[0], "----") !== false) {
$split_type = "----";
} else {
$split_type = "";
}
}
$cards = [];
foreach ($arr as $v) {
if (!empty($split_type)) {
$card = explode($split_type, $v);
} else {
$card = [$v, ''];
}
if (isset($card[0])) {
$card[0] = trim(html_entity_decode($card[0]), chr(0xc2) . chr(0xa0));
} else {
continue;
}
if ($card[0] === '') {
continue;
}
if (strlen($card[0]) > 255) {
continue;
}
// if(validateURL($card[0])) {//禁止url
// $this->error('虚拟卡内容不能包含链接');
// }
$number = $card[0];
if (isset($card[1])) {
$card[1] = trim(html_entity_decode($card[1]), chr(0xc2) . chr(0xa0));
} else {
continue;
}
if ($card[1] !== '') {
if (strlen($card[1]) > 255) {
continue;
}
$secret = $card[1];
} else {
$secret = '';
}
// 检查重复
if ($check_card == 1) {
$isExist =$this->db->where(['number' => $number, 'secret'=>$secret])->find();
if ($isExist) {
continue;
}
}
$cards[] = [
'number' => $number,
'secret' => $secret,
'status' => 1, // 未使用
];
}
if(!empty($cards))
{
$res = $this->db->insertAll($cards);
if (false !== $res) {
$this->success("操作成功,有效新增".$res.'条数据', weapp_url('Iplist/Iplist/index'));
}else{
$this->error("操作失败");
}
}else{
$this->success('虚拟卡内容格式不正确, 或卡密已存在', weapp_url('Iplist/Iplist/index'));
}
exit;
}
$this->assign('info', $info);
return $this->fetch('adddao');
}
thinkphp实现卡号卡密批量导入数据库方法教程-78模板网博客 - 一个分享技术、记录生活的个人技术博客
前端代码:
点击复制代码 Markup
<form class="form-horizontal" id="post_form" action="{:url('Ka/Ka/adddao')}" method="post">
<div class="ncap-form-default">
<dl class="row">
<dt class="tit">
<label>导入格式</label>
</dt>
<dd class="opt">
<div class="onoff">
<select name="split_type" class="form-control">
<option value="0">自动识别</option>
<option value=" ">用“ ”分隔</option>
<option value=",">用“,”分隔</option>
<option value="|">用“|”分隔</option>
<option value="----">用“----”分隔</option>
<option value="">不分隔</option>
</select>
</div>
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label>检查重复卡</label>
</dt>
<dd class="opt">
<div class="onoff">
<label for="target1" class="cb-enable selected">是</label>
<label for="target0" class="cb-disable ">否</label>
<input id="target1" name="check_card" value="1" type="radio" checked="checked">
<input id="target0" name="check_card" value="0" type="radio">
</div>
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label for="title"><em>*</em>ip+密码列表</label>
</dt>
<dd class="opt">
<textarea style="width:500px; height:350px;" name="content" id="content" placeholder="如:AAAAAAAAAAA BBBBBBBBBBBB"></textarea>
<span class="err"></span>
<p class="">提示:不允许为空,一行代表一个!</p>
</dd>
</dl>
<div class="bot" style="margin-top:10px;">
<input type="hidden" name="filename" id="filename" value="">
<a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
</div>
</div>
</form>
</div>
<script type="text/javascript">
// 判断输入框是否为空
function checkForm(){
if ($("#content").val() == '') {
showErrorMsg('ip+密码列表不能为空!');
$('#content').focus();
return false;
}
layer_loading('正在处理');
$('#post_form').submit();
}
</script>
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03