R
R
Robert Plant2021-01-18 21:50:03
1C-Bitrix
Robert Plant, 2021-01-18 21:50:03

How to import users into 1C-Bitrix?

There is a CSV file of the form:
LOGIN;NAME;EMAIL;PASSWORD;UF_FIELD_NAME
and, accordingly, there is data of the form:
ivan;Ivan;[email protected];Qwerty123;abcd The

question is how to import users with passwords? Passwords in unencrypted form.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2021-01-18
@o058oo

$csvData = file_get_contents('./people.csv');
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
    $array[] = str_getcsv($line);
}
print_r($array);

Result Example
Array
(
    [0] => Array
        (
            [0] => 12345
            [1] => Computers
            [2] => Acer
            [3] => 4
            [4] => Varta
            [5] => 5.93
            [6] => 1
            [7] => 0.04
            [8] => 27-05-2013
        )

    [1] => Array
        (
            [0] => 12346
            [1] => Computers
            [2] => Acer
            [3] => 5
            [4] => Decra
            [5] => 5.94
            [6] => 1
            [7] => 0.04
            [8] => 27-05-2013
        )

)


And here is the code for adding users, execute it in a loop
$user     = new CUser;
    $arFields = array(
        "NAME" => $name,
        "LOGIN" => $login,
        "EMAIL" => $email,
        "PHONE_NUMBER" => $phone,
        "LID" => "ru",
        "ACTIVE" => "Y",
        "PASSWORD" => $pass,
        "CONFIRM_PASSWORD" => $pass,
        "GROUP_ID" => array(10, 11)
    );
    $new_user_ID    = $user->Add($arFields);

before code
require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");

Help links
https://dev.1c-bitrix.ru/api_help/main/reference/c...
https://www.php.net/manual/ru/function.file-get-co...
https ://askdev.ru/q/php-csv-stroka-v-massiv-95815/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question