1
mjoel
Bulk user registration with xoops 2.5.8.1
  • 2017/3/2 0:03

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Hi

I would like to setup an intranet site with 400 plus users

i found a script here
https://xoops.org/modules/newbb/viewtopic.php?post_id=222145#222145
but its not working

<?php 
// christian@frxoops.org - http://www.frxoops.org 
// Import users from a csv file into XOOPS 2.0.x 
// variables 
$db"test"
$host"localhost"
$user"root"
$pass""
$fichier "users.csv"// data file as : user name;real name;email;password    
// remove line break on last record 

mysql_connect($host,$user,$pass) or die("Unable to connect Database"); 
mysql_select_db($db); 

// Open file for read 
if (file_exists($fichier)) 
    
$fp fopen("$fichier""r"); 
else{ 
// unknown file 
    
echo "File not found !Import stopped."
    exit(); 

echo 
'Begin file import '.$fichier.''
// import line by line 
while (!feof($fp)){ 
    
$ligne fgets($fp,4096); 
    
$liste explode(";",$ligne); // create array  
    
$user $liste[0]; //first field  
    
$name $liste[1]; //second field 
    
$email$liste[2]; 
    
$passmd5($liste[3]);     


    
// Add user in xoops_users table 
     
$query "insert into x536_users  (uname, name, email, pass) VALUES ('$user', '$name','$email','$pass')";

      
     
$resultmysql_query($query); 
     
$uid mysql_insert_id(); 
     
    
//Add user in group : users registered  
    
$numgroup ='2'
     
$query "INSERT INTO x536_groups_users_link  (groupid, uid) VALUES('$numgroup', '$uid')";
     
$resultmysql_query($query); 

     if (
mysql_error()){ 
      echo 
"Error in database : ".mysql_error(); 
      echo 
"Importation stoppée."
      
fclose($fp); 
      exit(); 
}else{ 
  echo 
"Record ".$uid." - ".$user." added "
 } 


echo 
"Import finished successfully."

fclose($fp);




anyone can help me so i can add user manually and give them a default password and they will change themsel

2
mjoel
Re: Bulk user registration with xoops 2.5.8.1
  • 2017/3/2 7:33

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


nevermind the code from here workshttp://dev.xoops.org/modules/xfmod/project/showfiles.php?group_id=1061&release_id=786&dl=2160

import_users.php
<?php
// christian@frxoops.org - http://www.frxoops.org
// Import users from a csv file into xoops 2.0.x
// 26 january 2006 : add trim() for encrypt password

// variables
$bdd"x20132";
$host"localhost";
$user"root";
$pass"";
$fichier "users.csv"// data file as : first name(pseudo);last name;email;password    
// remove line break on last record

mysql_connect($host,$user,$pass) or die("Unable to connect Database");
mysql_select_db($bdd);

// Open file for read
if (file_exists($fichier))
    
$fp fopen("$fichier""r");
else{ 
// unknown file
    
echo "File not found !Import stopped.";
    exit();
}
echo 
'Begin file import '.$fichier.'';
// import line by line
while (!feof($fp)){
    
$ligne fgets($fp,4096);
    
$liste explode(";",$ligne); // create array 
    
$user $liste[0]; //first field 
    
$name $liste[1]; //second field
    
$email$liste[2];
    
$passmd5(trim($liste[3]));    


    
// Add user in xoops_users table
     
$query "insert into xoops_users  (uname, name, email, pass) VALUES ('$user', '$name','$email','$pass')";

     
     
$resultmysql_query($query);
     
$uid mysql_insert_id();
    
    
//Add user in group : users registered 
    
$numgroup ='2';
     
$query "INSERT INTO xoops_groups_users_link  (groupid, uid) VALUES('$numgroup', '$uid')";
     
$resultmysql_query($query);

     if (
mysql_error()){
      echo 
"Error in database : ".mysql_error();
      echo 
"Importation stoppée.";
      
fclose($fp);
      exit();
}else{
  echo 
"Record ".$uid." - ".$user." added ";
 }
}

echo 
"Import finished successfully.";

fclose($fp);



users.csv
Bill;Barra;bill.barra@yahoo.com;245AVB
Mark
;Knopfler;mark@knopfler.com;AVB245
Jim
;Morrison;jim.morrison@gmail.com;bngh123
Roger
;Daltrey;roger@daltrey.com;XXD23


edit db prefix and it works although it can be improved with adding other field such as user_regdate

3
geekwright
Re: Bulk user registration with xoops 2.5.8.1

Try this script: import_users.php

It uses system handlers, so it should work in more modern systems.

4
mjoel
Re: Bulk user registration with xoops 2.5.8.1
  • 2017/3/3 1:47

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Thank you very much sir...it works perfectly

it will be more complete if it will check in the current db to prevent same username and email


<?php
/**
 * modified from script by christian@frxoops.org
 * Import users from a csv file into xoops 2.5.8
 *
 * Put this file and your users.cvs file in the root of your site
 * go to http://yoursite/import_users.php in your browser
 * click the button to rn the import
 *
 * Don't forget to DELETE it after you run it!
 */
/* Example users.csv file:
Bill;Barra;bill.barra@yahoo.com;changeme
Mark;Knopfler;mark@knopfler.com;changeme
Jim;Morrison;jim.morrison@gmail.com;changeme
Roger;Daltrey;roger@daltrey.com;changeme
*/
// assuming this is in the web root
include 'mainfile.php';
// make sure we run as a POST transaction, so database operations do not need "force"
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo 
'<form action="" method="POST"><input type="submit" value="Click to import"></form>';
    exit();
}
$fichier 'users.csv'// data file as : first name(pseudo);last name;email;password
// remove line break on last record
/** @var XoopsMemberHandler $memberHandler */
$memberHandler xoops_getHandler('member');
if (
false === $memberHandler) die("Unable to create member handler");
$time time();
// Open file for read
if (file_exists($fichier))
    
$fp fopen("$fichier""r");
else{ 
// unknown file
    
echo "File not found !Import stopped.n";
    exit();
}
echo 
'<pre>Begin file import '.$fichier."n";
// import line by line
while (!feof($fp)) {
    
$ligne fgets($fp4096);
    if (
'' === trim($ligne)) {
        continue; 
// blank line
    
}
    
$liste explode(";"$ligne); // create array
    
foreach ($liste as $index => $value) {
        
$liste[$index] = trim($value);
    }
    
/** @var XoopsUser $user */
    
$user $memberHandler->createUser();
    
$user->setVar('uname'$liste[0]);
    
$user->setVar('name'$liste[1]);
    
$user->setVar('email'$liste[2]);
    
$user->setVar('pass'md5($liste[3]));
    
$user->setVar('user_regdate'$time);
    
$user->setVar('user_level'1); // activated
    
$user->setVar('user_viewemail'1);
    
$user->setVar('user_avatar''avatars/blank.gif');
    
$uid $memberHandler->insertUser($user);
    if (
false === $uid) {
        echo 
sprintf("Failed to insert user %s n"$liste[0]);
        echo 
"Importation stoppée.n</pre>";
        
fclose($fp);
        exit();
    }
    
$memberHandler->addUserToGroup(XOOPS_GROUP_USERS$uid);
    echo 
sprintf("Record %d - %s addedn"$uid$user->uname());
}
echo 
"Import finished successfully.n</pre>";
fclose($fp);

Login

Who's Online

214 user(s) are online (132 user(s) are browsing Support Forums)


Members: 0


Guests: 214


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits