Use PHP to add users to Windows

Source: Internet
Author: User
1. add a user to the Web. because of adding a user, the user you run the PHP program must be the Administrator and your php. the security mode in ini is not enabled, and the closed function does not close system (), exec (),

  1. add users to the Web

To add users, the user you run the PHP program must be the Administrator and your php. the security mode in ini is not enabled, and the closed function does not close functions such as system (), exec (), passthru.

(For Windows 2003, Windows XP, and Windows)

1. use IIS as a Web server

For example, if IIS is used as the server, the account for running PHP is IUSR_XXXXXXXX, IWAM_XXXXXXX (XXXX indicates the computer name of the server ), then you must add these two users to the administrator Group: Administrators. Of course, if you do this, you will be blackmailed to the server.

2. use Apache as a Web server

As far as I know, after Apache is installed as a service, it will run with the system permission. that is to say, if PHP is run, it will directly be the system permission, which has exceeded the administrator permission, therefore, the performance of commands is even more difficult. If you have corrected the Apache running user, you must specify the Apache service running user as the administrator and above permissions, such as Administor or system permissions.

Then you can add user control in your PHP code:

The following code is described as required by the landlord:

Define ('User _ group', 'users'); // user group. The default value is users. for security purposes, the user group is defined.
Define ('active', 'yes'); // whether to activate the user directly after creation. if YES is activated, NO is not activated.

// Extract the user name and password from the database
// Assume that the table is user_info and only the field id, user, passwod
$ SQL = 'SELECT user, password FROM user_info ';
$ Result = mysql_query ($ SQL) or die ('query database failed ');
// Insert the data into the user cyclically
While ($ array = mysql_fetch_array ($ result )){
If (! Function_exists ('system '))
Die ('function system () not exists, add user failed .');
// Add a 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 adds all your database users to the local system. if you want to add a single user, you can consider changing it to adding the user after the user registration is successful. this can be expanded by yourself.

  2. add users by using php shell scripts

In addition, I have another idea. You can use php.exe on the server without a Security title. I just passed the test.

Suppose your php is installed in c: \ php \, then we will apply the command prompt to fulfill the php script to add users.

PHP code:

// C: \ test. php
@ System ('Net user heiyeluren test/add ');
?>
Stored in the c: \ test. php file
Perform the following in cmd:
C: \ php \ php.exe c: \ test. php
Tip:
C: \> c: \ php \ php.exe c: \ test. php
The command is successfully completed.

From this point of view, you can get the code that I wrote here to perform this operation. then php.exe acts as the shell script engine. Then write batch processing and perform it through scheduled tasks. Of course, you can also consider using other languages, such as vb/vc, to regularly search the database for new users and then add them to the system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.