This can be achieved in two ways.
1. Add users to the Web
. Because of adding users, the user you run the PHP program must have administrator rights (Administrator), and at the same time, the safe mode in your php.ini must not be turned on, and the system() must not be closed in the shutdown function. ), exec(), passthru() and other functions.
(The following instructions are for Windows2000/Windows XP/Windows 2003)
1. Use IIS as the Web server. If you use IIS as the server, then the account running PHP is: IUSR_XXXXXXXX, IWAM_XXXXXXX, (XXXX represents the computer name of the server), then you must Add these two users to the Administrators group: Administrators. Of course, if you do this, it will pose a threat to server security.
1. Use Apache as a Web server. As far as I know, after Apache is installed as a service, it runs with system permissions. That means that when PHP is run, it directly has system permissions, which exceeds administrator permissions, so it is no longer possible to execute commands. Next words. If you modify the running user of Apache, then you must specify that the running user of the Apache service has administrator or higher permissions, such as Administrator or system permissions.
Then you can perform the add user operation in your PHP code:
According to the poster's needs, describe the following code:
<?php
define("USER_GROUP", "users"); //User group, the default is users, for security reasons, define the user group
define("ACTIVE", "YES"); //Whether to activate the user directly after creation, YES means activation, NO means inactivation
//Extract the user name and password from the database
//Assume the table is user_info and only has the fields id, user, passwod
$sql = "SELECT user,password FROM user_info";
$result = mysql_query($sql) or die("Query database failed");
//Loop to insert users
while ($array = mysql_fetch_array($result)) {
if (!function_exists("system"))
die('Function system() not exists, add user failed.');
//Add user
@system("net user $array[user] $array[passwd] /active:ACTIVE /add");
//Add to specified group
@system("net localgroup users $array[user] /del");
@system("net localgroup USER_GROUP $array[user] /add");
}
?>
The above code adds users of all your databases to the local system. If you want to add them individually, you can consider changing it to add users after successful user registration. This can be expanded by yourself.
2. Use PHP as a shell script to add users.
In addition, I actually have another idea. It can be executed using php.exe on the server side without any security issues. I just took the test and it passed.
Assuming that your php is installed in c:php, then we use the command prompt to execute the php script to add users.
PHP code:
//c:test.php
<?php
@system("net user heiyeluren test /add");
?>
Save it in the c:test.php file and execute it under cmd:
c:phpphp.exe c:test.php
hint:
C:>c:phpphp.exe c:test.php
The command completed successfully.
So from this perspective, the code I wrote above can be brought here to be executed, and then php.exe acts as a shell script engine. Then write it as a batch process and execute it through scheduled tasks. Of course, you can also consider using other languages to implement it, such as vb/vc. Regularly search the database to see if there are newly added users, and then add the users to the system.