How to use PHP to add users to windows _ PHP Tutorial

Source: Internet
Author: User
How to use PHP to add users to windows. The method is as follows: because users are added, the user you run the PHP program must be the Administrator and your php. the security mode in ini is not enabled, and the related methods are as follows:

Because users are added, the user you run the PHP program must be Administrator and your php. the security mode in ini is not enabled, and the system (), exec (), passthru (), and other functions are not disabled in the function.

(For Windows2000, Windows XP, and Windows 2003)
1. use IIS as a Web server
If IIS is used as the server, the account for running PHP is IUSR_XXXXXXXX, IWAM_XXXXXXX (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 threaten the server security.

II. use Apache as a Web server
It is understood that 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 command execution will be skipped. If you have modified 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 users in your PHP code:
The following code is described:




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 users 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.

However, this method cannot be synchronized.

Method 2:
You can use php.exe on the server without any security issues.

If your php is installed in c: \ php \, run the command prompt to run the php script to add users.

PHP code:
// C: \ test. php
@ System ("net user test/add ");
?>
Save it in the c: \ test. php file
Run the following command in cmd:
C: \ php \ php.exe c: \ test. php
Tip:
C: \> c: \ php \ php.exe c: \ test. php
The command is successfully completed.

Then, the code in the same region is taken here for execution. then, php.exe acts as the shell script engine. Write batch processing and execute it through scheduled tasks. Of course, you can also consider using other languages, such as vb/vc, to regularly search for new users in the database and then add them to the system.

Because users are added, the user you run the PHP program must be the Administrator, and the security mode in your php. ini is not enabled and off...

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.