Home Backend Development PHP Tutorial 这种入口网页如何做

这种入口网页如何做

Jun 13, 2016 pm 12:02 PM
http nbsp php server

这种入口网页怎么做?
   例如我们大学里有Wifi可以上网,但要账号密码。用电脑或者手机一上网,就先出现一个登陆的网页(我这里称之为“入口网页”,不知这样称呼是否准确?还是该叫“门户网页”?),输了账号密码,点一个“上线”按钮,然后页面提示已经上线。然后就可以自由访问其他网站网页了。
    这种入口网页很多的,随便走到街上,就发现有ChinaNet、CMCC、ChinaUnicom这些看似没有加锁的Wifi,但你要是连接了这些网络,一上网,第一个页面也是要你输账号密码,你有账号密码才可以通过这个入口然后自由上网。不仅是WiFi,有些小区的以太网也是这样的,以前我住的一个小区,长城宽带,也是这样的上网方式,要先经过一个入口网页输账号密码。

    我想知道这样的网页怎么做?是怎样通过一个网页去控制局域网内用户的上网权限的? 

    我有个项目需要做个这样的网页,急!大家帮帮我呀!跪谢!
------解决方案--------------------
类似一种代理....
------解决方案--------------------
这种网关主要任务是权限控制然后路由数据包,相对于一般的web服务器,他应该在更底层实现,我猜登录页面只是个CGI,主程序是高性能C/java基于socket工作
不太懂,很感兴趣关注下
------解决方案--------------------
你们好像都忘了这个。让你们看手册吧,又不大愿意。干脆贴吧

章 34. 用 PHP 进行 HTTP 认证<br>PHP 的 HTTP 认证机制仅在 PHP 以 Apache 模块方式运行时才有效,因此该功能不适用于 CGI 版本。在 Apache 模块的 PHP 脚本中,可以用 header() 函数来向客户端浏览器发送“Authentication Required”信息,使其弹出一个用户名/密码输入窗口。当用户输入用户名和密码后,包含有 URL 的 PHP 脚本将会加上预定义变量 PHP_AUTH_USER,PHP_AUTH_PW 和 AUTH_TYPE 被再次调用,这三个变量分别被设定为用户名,密码和认证类型。预定义变量保存在 $_SERVER 或者 $HTTP_SERVER_VARS 数组中。支持“Basic”和“Digest”(自 PHP 5.1.0 起)认证方法。请参阅 header() 函数以获取更多信息。 <br><br>PHP 版本问题: Autoglobals 全局变量,包括 $_SERVER等,自 PHP 4.1.0 起有效,$HTTP_SERVER_VARS 从 PHP 3 开始有效。 <br><br>以下是在页面上强迫客户端认证的脚本范例: <br><br>例子 34-1. Basic HTTP 认证范例<br><br><?php <br />  if (!isset($_SERVER['PHP_AUTH_USER'])) {<br>    header('WWW-Authenticate: Basic realm="My Realm"');<br>    header('HTTP/1.0 401 Unauthorized');<br>    echo 'Text to send if user hits Cancel button';<br>    exit;<br>  } else {<br>    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";<br>    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";<br>  }<br>?>  <br> <br><br><br>例子 34-2. Digest HTTP 认证范例<br><br>本例演示怎样实现一个简单的 Digest HTTP 认证脚本。更多信息请参考 RFC 2617。 <br><br><?php <br />$realm = 'Restricted area';<br><br>//user => password<br>$users = array('admin' => 'mypass', 'guest' => 'guest');<br><br><br>if (!isset($_SERVER['PHP_AUTH_DIGEST'])) {<br>    header('HTTP/1.1 401 Unauthorized');<br>    header('WWW-Authenticate: Digest realm="'.$realm.<br>           '" qop="auth" nonce="'.uniqid().'" opaque="'.md5($realm).'"');<br><br>    die('Text to send if user hits Cancel button');<br>}<br><br>// analize the PHP_AUTH_DIGEST variable<br>preg_match('/username="(?P<username>.*)",\s*realm="(?P<realm>.*)",\s*nonce="(?P<nonce>.*)",\s*uri="(?P<uri>.*)",\s*response="(?P<response>.*)",\s*opaque="(?P<opaque>.*)",\s*qop=(?P<qop>.*),\s*nc=(?P<nc>.*),\s*cnonce="(?P<cnonce>.*)"/', $_SERVER['PHP_AUTH_DIGEST'], $digest);<br><br>if (!isset($users[$digest['username']]))<br>    die('Username not valid!');<br><br><br>// generate the valid response<br>$A1 = md5($digest['username'] . ':' . $realm . ':' . $users[$digest['username']]);<br>$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$digest['uri']);<br>$valid_response = md5($A1.':'.$digest['nonce'].':'.$digest['nc'].':'.$digest['cnonce'].':'.$digest['qop'].':'.$A2);<br><br>if ($digest['response'] != $valid_response)<br>    die('Wrong Credentials!');<br><br>// ok, valid username & password<br>echo 'Your are logged in as: ' . $digest['username'];<br><br>?>  <br> <br><br><br>兼容性问题: 在编写 HTTP 标头代码时请格外小心。为了对所有的客户端保证兼容性,关键字“Basic”的第一个字母必须大写为“B”,分界字符串必须用双引号(不是单引号)引用;并且在标头行 HTTP/1.0 401 中,在 401 前必须有且仅有一个空格。 <br><br>在以上例子中,仅仅只打印出了 PHP_AUTH_USER 和 PHP_AUTH_PW 的值,但在实际运用中,可能需要对用户名和密码的合法性进行检查。或许进行数据库的查询,或许从 dbm 文件中检索。 <br><br>注意有些 Internet Explorer 浏览器本身有问题。它对标头的顺序显得似乎有点吹毛求疵。目前看来在发送 HTTP/1.0 401 之前先发送 WWW-Authenticate 标头似乎可以解决此问题。 <br><br>自 PHP 4.3.0 起,为了防止有人通过编写脚本来从用传统外部机制认证的页面上获取密码,当外部认证对特定页面有效,并且安全模式被开启时,PHP_AUTH 变量将不会被设置。但无论如何,REMOTE_USER 可以被用来辨认外部认证的用户,因此可以用 $_SERVER['REMOTE_USER'] 变量。 <br><br>配置说明: PHP 用是否有 AuthType 指令来判断外部认证机制是否有效。 <br><br>注意,这仍然不能防止有人通过未认证的 URL 来从同一服务器上认证的 URL 上偷取密码。 <br><br>Netscape Navigator 和 Internet Explorer 浏览器都会在收到 401 的服务端返回信息时清空所有的本地浏览器整个域的 Windows 认证缓存。这能够有效的注销一个用户,并迫使他们重新输入他们的用户名和密码。有些人用这种方法来使登录状态“过期”,或者作为“注销”按钮的响应行为。 <br><br>例子 34-3. 强迫重新输入用户名和密码的 HTTP 认证的范例<br><br><?php <br />  function authenticate() {<br>    header('WWW-Authenticate: Basic realm="Test Authentication System"');<br>    header('HTTP/1.0 401 Unauthorized');<div class="clear">
                 
              
              
        
            </div></cnonce></nc></qop></opaque></response></uri></nonce></realm></username>
Copy after login
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

See all articles