Php 将基本身份验证转发到表单?

Php 将基本身份验证转发到表单?,php,authentication,forms-authentication,basic-authentication,Php,Authentication,Forms Authentication,Basic Authentication,好吧,但是我不知道是否有人尝试过这样做 我有一个网站,我们就叫它localhost。现在。我在那一页上有一张表格。但是,我希望能够跳过表单,并使用基本身份验证方法将数据重定向到表单。例如:将用户名和密码发送到我的表单 有没有办法不用我修改整个网站就可以做到这一点? 您不需要将其发送到表单 你可以这样做 if(!isset($_SESSION['admin'])){ //we are not logged in yet, if (!isset($_SERVER['

好吧,但是我不知道是否有人尝试过这样做

我有一个网站,我们就叫它localhost。现在。我在那一页上有一张表格。但是,我希望能够跳过表单,并使用基本身份验证方法将数据重定向到表单。例如:将用户名和密码发送到我的表单

有没有办法不用我修改整个网站就可以做到这一点?



您不需要将其发送到表单

你可以这样做

if(!isset($_SESSION['admin'])){
        //we are not logged in yet,
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
                header('WWW-Authenticate: Basic realm="Admin"');
                header('HTTP/1.0 401 Unauthorized');
                echo 'Please Contact us if you are having problems logging in';
                exit;
        } else {
                //not their first time through
                //check their username and password here
                $username = trim($_SERVER['PHP_AUTH_USER']);
                $password = trim($_SERVER['PHP_AUTH_PW']);
                ... your auth code here....  
if(!isset($_SESSION['admin'])){
        //we are not logged in yet,
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
                header('WWW-Authenticate: Basic realm="Admin"');
                header('HTTP/1.0 401 Unauthorized');
                echo 'Please Contact us if you are having problems logging in';
                exit;
        } else {
                //not their first time through
                //check their username and password here
                $username = trim($_SERVER['PHP_AUTH_USER']);
                $password = trim($_SERVER['PHP_AUTH_PW']);
                ... your auth code here....