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

发布于 2024-09-14 10:03:51 字数 263 浏览 7 评论 0原文

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

我有一个网站,我们可以将其称为 localhost。目前。我在该页面上有一个表格。但是,我希望能够跳过该表单,并使用基本身份验证方法将我的数据重定向到该表单。例如: http://admin:admin@localhost 会将用户名和密码发送到我的表单。

有没有办法做到这一点而无需我修改整个网站?

Alright, I don't know if anyone has tried to do this yet, however.

I have a website lets just call it localhost. for now. I have a form on that page. however, I want to be able to skip the form, and redirect my data to the form by using the basic authentication method. for example: http://admin:admin@localhost would send the username and password to my form.

Is there a way to do that without me having to modify the entire website?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰雪之触 2024-09-21 10:03:51

您不需要将其发送到表格。

你可以做这样的事情

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....  

you don't need to send it to the form.

you can do something like this

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....  
眼泪也成诗 2024-09-21 10:03:51

使用 $_SERVER 数组非常简单。

<form>
  <input name="username" value="<?php echo $_SERVER['PHP_AUTH_USER']; ?>">
  <input type="password" value="<?php echo $_SERVER['PHP_AUTH_PW']; ?>">
</form>

Very easy using the $_SERVER array.

<form>
  <input name="username" value="<?php echo $_SERVER['PHP_AUTH_USER']; ?>">
  <input type="password" value="<?php echo $_SERVER['PHP_AUTH_PW']; ?>">
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文