<?php // 用户列表 $user_list = ['user' => 'password']; $user = $_SERVER['PHP_AUTH_USER']; $pass = $_SERVER['PHP_AUTH_PW']; if ((@$user_list[$user] ?: '') !== $pass) { header('WWW-Authenticate: Basic realm="用户登录"'); header('HTTP/1.0 401 Unauthorized'); die("未登录"); } // 登录成功 echo "<p>Welcome $user.</p>";
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]