Table of Contents
Not Found
Home Backend Development PHP Tutorial PHP用户认证及管理完全源码_PHP

PHP用户认证及管理完全源码_PHP

Jun 01, 2016 pm 12:40 PM
echo Source code user manage Certification

-- begin auth.inc --  




$id = "xxxCOM";  


if(!isset($PHP_AUTH_USER)) {  

Header("WWW-Authenticate: Basic realm="$id"");  

Header("HTTP/1.0 401 Unauthorized");  

require('error.inc');  

exit;  

}  


$name = $PHP_AUTH_USER;  

$pass = $PHP_AUTH_PW;  

require("connect.inc");  

$query = "select * from auth where username='$name' && realm='$id'";  

$result = mysql_db_query("admin", $query);  

if(mysql_num_rows($result) == 0) {  


Header("WWW-Authenticate: Basic realm="$id"");  

Header("HTTP/1.0 401 Unauthorized");  

require('error.inc');  

exit;  

}  


$active = mysql_result($result,0,"active");  

if($active == 'no') {  


?>  

  

404 Not Found  

  

Not Found

  

The requested URL  

echo $REQUEST_URI; ?>  

was not found on this server.

  

  


exit;  

}  

?>  


-- end auth.inc --  


-- begin connect.inc --  


  


-- end connect.inc --  


-- begin error.inc --  


此文件存放错误信息及返回!  


-- end error.inc --  


-- 用户库结构(自己调整)--  


CREATE TABLE auth (  

id smallint(6) DEFAULT '0' NOT NULL auto_increment,  

username varchar(16) DEFAULT ' NOT NULL,  

lastname tinyblob,  

firstname tinyblob,  

password varchar(16),  

realm varchar(16),  

active char(3),  

PRIMARY KEY (id),  

UNIQUE id (id),  

UNIQUE username (username)  

);  


-- 用户库结构结束--  


-- 添加用户示例--  


insert into auth (username, lastname, firstname, password, realm, active) values ('admin','my','love','password','xxxCOM','yes');  


-- 结束--  


--用户管理程序开始 usermanage.php --  

  



if ($PHP_AUTH_USER != "admin") {  

Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");  

Header("HTTP/1.0 401 Unauthorized");  

echo "Access Denied!n";  

exit;  

};  


if ($PHP_AUTH_PW != "mypassword") {  

Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");  

Header("HTTP/1.0 401 Unauthorized");  

echo "Access Denied!n";  

exit;  

};  


if ($activate) {  


include("connect.inc");  

$query1 = "UPDATE auth SET active='yes' where id='$id'";  

$result1 = mysql_db_query("admin", $query1);  


if ($result1) {  

echo "n";  

echo "$user activatedn";  

echo "
n返回n";  

echo "
n";  

exit;  

} else {  

echo "n";  

echo "Error: Unknown Errorn";  

echo "
n返回n";  

echo "
n";  

exit;  

}  


}  


if ($deactivate) {  


include("connect.inc");  

$query2 = "UPDATE auth SET active='no' where id='$id'";  

$result2 = mysql_db_query("admin", $query2);  


if ($result2) {  

echo "n";  

echo "$user deactivatedn";  

echo "
n返回n";  

echo "
n";  

exit;  

} else {  

echo "n";  

echo "Error: Unknown Errorn";  

echo "
n返回n";  

echo "
n";  

exit;  

}  


}  


if ($delete) {  


include("connect.inc");  

$query3 = "delete from auth where id='$id'";  

$result3 = mysql_db_query("admin", $query3);  


if ($result3) {  

echo "n";  

echo "$user 已删除!n";  

echo "
n返回n";  

echo "
n";  

exit;  

} else {  

echo "n";  

echo "Error: Unknown Errorn";  

echo "
n返回n";  

echo "
n";  

exit;  

}  


}  


echo "n";  

echo "

n";  

echo "用户管理n";  

echo "n";  

echo "n";  

echo "
n";  

echo "n";  

echo "n";  


include("connect.inc");  

$query = "SELECT * FROM auth";  

$result = mysql_db_query("admin", $query);  


if ($result) {  

while ($r = mysql_fetch_array($result)) {  

$id = $r["id"];  

$username = $r["username"];  

$lastname = $r["lastname"];  

$firstname = $r["firstname"];  

$activated = $r["active"];  

if ($activated == "yes") {  

echo "n";  

} elseif ($activated == "no") {  

echo "n";  

}  

}  

}  

mysql_free_result($result);  

echo "
Username Real Name Activated
$username $lastname, $firstname $activated Deactivate Delete
$username $lastname, $firstname $activated Activate Delete
n";  

echo "n";  

echo "n";  


?>  


-- usermanage.php 结束--  
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Xiaohongshu account to find users? Can I find my mobile phone number? How to use Xiaohongshu account to find users? Can I find my mobile phone number? Mar 22, 2024 am 08:40 AM

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

Log in to Ubuntu as superuser Log in to Ubuntu as superuser Mar 20, 2024 am 10:55 AM

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

What is sudo and why is it important? What is sudo and why is it important? Feb 21, 2024 pm 07:01 PM

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and

Analysis of user password storage mechanism in Linux system Analysis of user password storage mechanism in Linux system Mar 20, 2024 pm 04:27 PM

Analysis of user password storage mechanism in Linux system In Linux system, the storage of user password is one of the very important security mechanisms. This article will analyze the storage mechanism of user passwords in Linux systems, including the encrypted storage of passwords, the password verification process, and how to securely manage user passwords. At the same time, specific code examples will be used to demonstrate the actual operation process of password storage. 1. Encrypted storage of passwords In Linux systems, user passwords are not stored in the system in plain text, but are encrypted and stored. L

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ​​are springing up like mushrooms after a rain. One of the languages ​​that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Oracle Database: Can one user have multiple tablespaces? Oracle Database: Can one user have multiple tablespaces? Mar 03, 2024 am 09:24 AM

Oracle database is a commonly used relational database management system, and many users will encounter problems with the use of table spaces. In Oracle database, a user can have multiple table spaces, which can better manage data storage and organization. This article will explore how a user can have multiple table spaces in an Oracle database and provide specific code examples. In Oracle database, table space is a logical structure used to store objects such as tables, indexes, and views. Every database has at least one tablespace,

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

One-line command to find all real users in Linux One-line command to find all real users in Linux Feb 18, 2024 pm 05:50 PM

Hello everyone, I am Xianyu. Friends who have been exposed to Linux all know that there are three types of users in Linux (or Unix-like): Super user (UID 0): the root user, who has the highest permissions. System user (UID 1~999): System built-in user, used to run system services and daemon processes. Ordinary user (UID 1000~60000): Created to allow users to use Linux system resources. The account created by the user is generally an ordinary account. So now the question is, how to quickly find out the real users (root users and ordinary users) in Linux? Before we officially start, we first introduce a tool-getent. getent

See all articles