Home  >  Article  >  Backend Development  >  Use PHP to add users to Windows system_PHP tutorial

Use PHP to add users to Windows system_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:32:12861browse

It can be achieved, there are two methods.

1. Add users to the Web

Because of adding users, you run php (as the current mainstream development language) The user of the program must have administrator rights (Administrator), and at the same time you need your php(as the current mainstream development language). The safe mode in ini is not turned on, and the system(), exec(), passthru() are not turned off in the shutdown function. ) and other functions.

(The following instructions are for Windows2000/Windows XP/Windows 2003)

1. Use iis(Microsoft's WEB server platform)to make a Web server
If you use If iis(Microsoft's WEB server platform) is used as a server, then the account running php(as the current mainstream development language) is: IUSR_XXXXXXXX, IWAM_XXXXXXX, (XXXX represents the server's computer name), then you must add these two users to the administrator group: Administrators. Of course, if you do this, it will pose a threat to server security.

1. Use apache (the most popular WEB server platform on the Unix platform) as the Web server
As far as I know, apache (the most popular WEB server platform on the Unix platform) After it is installed as a service, it will run with system permissions, that is to say, if php(as the current mainstream development language) is run, it will directly have system permissions, which has exceeded the administrator permissions. Then executing the command is no longer a problem. If you modify the running user of apache(The most popular WEB server platform on Unix platform), then you must specify the running user of apache(The most popular WEB server platform on Unix platform) service Administrator or above permissions, such as Administrator or system permissions.

Then you can perform the add user operation in your php(as the current mainstream development language) code:

According to the poster’s needs, the description is as follows Code:

(as the current mainstream development language)
define("USER_GROUP", "users"); //User group, the default is users, For the sake of security, define the user group
define("ACTIVE", "YES"); //Whether to activate the user directly after creation, YES means activation, NO means inactivation

//Extract from the database Username and password
//Assume the table is user_info, and there are only fields id, user, passwod
$sql = "SELECT user, password FROM user_info";
$result = MySQL(matched with PHP The best combination)_query($sql) or die("Query database failed");
//Loop insert users
while ($array = MySQL(The best combination with PHP combination)_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 the specified group
@system("net localgroup users $array[ user] /del");
@system("net localgroup USER_GROUP $array[user] /add");
}
?>

The above code implements all your databases Users are added 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 the current mainstream development language) Make a shell script to add users

In addition, I actually have another idea. You can use php(as the current mainstream development language).exe to execute on the server side, and there will be no security issues. I just took the test and it passed.

Assume that your php(as the current mainstream development language) is installed in c:php(as the current mainstream development language), then we will Use the command prompt to execute the php(as the current mainstream development language) script to add users.

php(as the current mainstream development language)Code:
//c: est.php(as the current mainstream development language)
(as the current mainstream development language)
@system("net user heiyeluren test /add");
?>
Save in c: est .php(as the current mainstream development language) file
is executed under cmd:
c:php(as the current mainstream development language)php(as the current mainstream development language).exe c: est.php(as the current mainstream development language)
Tip:
C:>c:php (as the current mainstream development language)php(as the current mainstream development language).exe c: est.php(as the current mainstream development language)
The command completed successfully.

So from this point of view, you can take the code I wrote above and execute it here, and then php(as the current mainstream development language).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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508727.htmlTechArticle can be achieved, there are two methods. 1. Add a user to the Web. Because you add a user, the user running the php (as the current mainstream development language) program must have administrator rights (Admini...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn