Add user_php to Windows using PHP

Source: Internet
Author: User
Use PHP to add users to Windows. It can be implemented in two ways. 1. add users to the Web. because users are added, the user you run the php (as the mainstream development language) program must be the administrator privilege (which can be implemented by Admini. There are two methods.

1. add users to the Web

Because users are added, the user you run php (as the current mainstream development language) must be Administrator ), you also need your php (as the mainstream development language ). 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 (Microsoft's WEB server platform) as a Web server
If you use iis (Microsoft's WEB server platform) as the server, the account that runs php (as the current mainstream development language) is IUSR_XXXXXXXX, IWAM_XXXXXXX, (XXXX indicates the computer name of the server), you must add these two users to the administrator Group: Administrators. Of course, if you do this, it will threaten the server security.

1. use apache (the most popular WEB server platform on Unix) as a Web server
As far as I know, after apache (the most popular WEB server platform on the Unix platform) is installed as a service, it runs with the system permission. that is to say, php (as the mainstream development language) if the system permission is exceeded by the administrator, the command execution will be skipped. If you have modified the running user of apache (the most popular WEB server platform on the Unix platform), you must specify apache (the most popular WEB server platform on the Unix platform) the service running user has the administrator and above permissions, such as Administor or system permissions.

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

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 (the best combination with PHP) _ query ($ SQL) or die ("Query database failed ");
// Insert users cyclically
While ($ array = MySQL (the best combination with PHP) _ 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. use php (as the mainstream development language) as a shell script to add users

In addition, I have another idea. You can use PHP (as the current development language cmd.exe on the server side, without any security issues. I just passed the test.

Suppose your php (as the mainstream development language) is installed in c: php (as the mainstream development language, then we will use the command prompt to execute php (as the current mainstream development language) scripts to add users.

Php (as the mainstream development language) Code:
// C: est. php (as the mainstream development language)
@ System ("net user heiyeluren test/add ");
?>
Stored in the c: est. php (as the mainstream development language) file
Run the following command in cmd:
C: php (use the current development language php(use the current development language cmd.exe c: est. php (as the current mainstream development language)
Tip:
C:> c: php (current development language: php) (current development language: .exe c: est. php (as the mainstream development language)
The command is successfully completed.

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

Second, there are two methods. 1. add users to the Web. because users are added, the user you run the php (as the mainstream development language) program must be the administrator privilege (Admini...

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.