How to use PHP to add users _php tips to Windows

Source: Internet
Author: User
The method has one:

Because you are adding users, the user who runs the PHP program must be an administrator, and the security mode in your php.ini is not turned on, and the function of system (), exec (), PassThru () is not turned off in the shutdown function.

(The following instructions are for Windows2000/windows xp/windows 2003)
One, use IIS to do the Web server
If you are using IIS as a server, then the account running PHP is: Iusr_xxxxxxxx,iwam_xxxxxxx, (xxxx represents the server's computer name), then you have to add these two users to the Administrators group: Administrators. Of course, if you do this, it will pose a threat to server security.

Second, using Apache as a Web server
It is understood that Apache installed into the service, then it is operating with the system permissions, so that is the case of PHP running, directly is the system permissions, has exceeded the administrator rights, then execute the command more than words. If you modify the Apache running user, you must specify that the Apache service run user is administrator above, such as administor or system privileges.
You can then perform the Add user action in your PHP code:
Describes the following code:




<?php
Define ("User_group", "users"); User group, default to users, for security, define still user group
Define ("ACTIVE", "yes"); Whether to activate the user directly after creation, yes to activate, no to Inactive

Extracting user names and passwords from the database
Suppose 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");
Loop Insert User
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 specified group
@system ("net localgroup users $array [user]/del");
@system ("net localgroup user_group $array [USER]/add");
}
?>

The above code to add all of your database users to the local system, if you want to add a single, you can consider changing the user registration after the successful add users, this can expand their own.

However, this method does not implement synchronization

Method Two:
Php.exe can be used on the server side, and there are no security issues.

If your PHP is installed in c:\php\, then we use a command prompt to execute PHP scripts to add users.

PHP Code:
c:\test.php
<?php
@system ("NET user test Test/add");
?>
Save in c:\test.php file
Execute under CMD:
C:\php\php.exe c:\test.php
Tips:
C:\>c:\php\php.exe c:\test.php
Command completed successfully.

The code in method one is then taken here to execute, and php.exe acts as the shell script engine. It is then written as a batch process and executed by a timed task. Of course, you can also consider using other languages to implement, such as VB/VC, and periodically go to the database to retrieve whether there are new users added, and then add users 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.