首先,你得知道debug网页请求- -因为要用到cookie,不知道怎么提取登录admin管理后台的cookie就甭看了。

然后,修改:

source\class\helper\helper_form.php

showmessage('submit_invalid');

上一行添加:

return TRUE;

即:
变为:

			} else {
return TRUE;
showmessage('submit_invalid');
}

按以下导入用户数据格式保存为user.txt:

用户名|邮箱|密码,用户名|邮箱|密码

PHP代码(注意设置你的域名,cookie进去):

<?php
$domain = "127.0.0.1";#设置你的域名
$cookie = '';#设置你debug登录admin管理后台后的cookie
$c = file_get_contents("user.txt");#指定用户列表文件
$c = explode(",",$c);
foreach($c as $val){
    $tmp = explode("|",$val);
    $name = $tmp[0];
    $pw = $tmp[2];
    $mail = $tmp[1];
    echo $name."\t";
    echo $pw."\t";
    echo $mail."\n";
	$ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'formhash=cbe14679&scrolltop=&anchor=&newusername='.UrlEncode($name).'&newpassword='.UrlEncode($pw).'&newemail='.UrlEncode($mail).'&newgroupid=10&emailnotify=0&addsubmit=%E6%8F%90%E4%BA%A4');
	curl_setopt($ch, CURLOPT_URL, 'http://'.$domain.'/admin.php?action=members&operation=add');
	curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
	curl_setopt($ch, CURLOPT_TIMEOUT, 60);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
	$r = curl_exec($ch);
	if (curl_errno($ch)) {
		echo 'error3: ' . curl_error($ch)."\r\n";
	}
	curl_close($ch);
    echo getmystring($r,'infotitle2">','</h4>')."\n";
}


function getmystring($str,$beginstr='',$endstr,$beginpos=0){
	if($beginstr==''){
	    $firstpos=0;
	}else{
	    $firstpos=strpos($str,$beginstr,$beginpos)+strlen($beginstr);
	}
    $secondpos=strpos($str,$endstr,$firstpos);
	if($secondpos===false){
		$returnstr=substr($str,$firstpos);
	}else{
		$returnstr=substr($str,$firstpos,$secondpos-$firstpos);
	}
    return $returnstr;
}

然后执行php代码即可批量导入用户。导入完,还原以下文件的更改。

source\class\helper\helper_form.php

思路来自:http://blog.csdn.net/change518/article/details/50555301

Related Posts: DiscuzX3.3 批量添加用户 PHP脚本 :