How to add users to windows using PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:59:48
Original
1030 people have browsed it

There is one method:

Because you are adding a user, 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 shutdown function must not be closed. System(), exec(), passthru() and other functions.

( The following instructions are for Windows2000/Windows (XXXX represents the computer name of the server), 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.

2. Use Apache as a Web server
It is understood that after Apache is installed as a service, it runs with system permissions, which means that when PHP is run, it directly has system permissions, which has exceeded the administrator permissions, then executing commands is no longer a problem. 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:
Describe the following code:




define( "USER_GROUP", "users"); //User group, the default is users, for security, the definition is still the user group
define("ACTIVE", "YES"); //Whether to activate the user directly after creation, YES To activate, NO means not to activate

//Extract the user name and password from the database
//Assume the table is user_info, and there are only fields id, user, password
$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 the specified group
@system("net localgroup users $array[user] /del");
@system ("net localgroup USER_GROUP $array[user] /add"); For addition, you can consider changing it to add users after successful user registration. This can be expanded by yourself.

However, this method cannot achieve synchronization

Method 2:
Can be executed using php.exe on the server side, and there will be no security issues.

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
@system("net user test test /add");
?>
Save in c:test.php file
Execute under cmd:
c:phpphp.exe c:test.php
Tips:
C:>c:phpphp.exe c: test.php
The command completed successfully.

Then take the code in method one here and execute it, 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.



http://www.bkjia.com/PHPjc/317278.html

www.bkjia.com

true

TechArticleOne method: Because adding a user, the user you run the PHP program must have administrator rights (Administrator), and At the same time, the safe mode in your php.ini needs to be turned off and turned off...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template