Http基本身份验证的登录表单 [英] Login Form For Http Basic Auth

查看:202
本文介绍了Http基本身份验证的登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行名为bitlfu的 Perl 应用程序。对于登录,它使用的是类似于 Apache HTTP基本身份验证但不是表单。我想为登录用户名和密码字段。
我尝试过JavaScript和PHP,直到现在都没有结果。



所以我需要帮助!

PS:
这种类型的网址作品

  http:// user:password@host.com 


解决方案

b

  document.location ='http://'+ user +':'+ pass +'@ mydomain.tld'; 

应该完成这项工作。



基本上,你必须创建一个表单,用户和传递字段,然后onsubmit,使用这里给出的JavaScript部分:

 < form method =postonsubmit =javascript:document.location ='http://'+ $('login')+':'+ $('pass')+'@ mydomain.tld'; > 
< input type =textname =loginid =login/>
< input type =passwordname =passid =pass/>
< input type =submitvalue =ok/>
< / form>

其中$()是一个document.getElementById或jquery左右。我使用$()函数来缩短代码。这是一个实现,它不适用于每个浏览器。再看看jQuery的跨浏览器解决方案。

  function $(_ id){return document.getElementById(_id); } 

否则,您可以使用php并使用标头位置重定向用户。



php方式:

 <?php 

if (isset($ _ POST ['login'])&& isset($ _ POST ['password'])){header('Location:'。urlencode($ _ POST ['login'])。':'。urlencode ($ _POST ['password'])。'@ domain.tld'); }
else
{
?>
< form method =postonsubmit =javascript:document.location ='http://'+ $('login')+':'+ $('pass')+'@mydomain。 TLD';>
< input type =textname =loginid =login/>
< input type =passwordname =passid =pass/>
< input type =submitvalue =ok/>
< / form>

<?php
}


I am running a Perl application named bitlfu.For login it is using something like Apache HTTP Basic Auth but not a form.I want to make form for the login with username and password field. I have tried JavaScript and PHP with no results till now.

So I need help!

PS: this kind of url works

http://user:password@host.com

解决方案

I think a simple JavaScript like:

document.location='http://' + user + ':' + pass + '@mydomain.tld';

should do the work.

So basically, you have to create a form, with a user and pass field, then onsubmit, use the part of JavaScript given here:

<form method="post" onsubmit="javascript:document.location='http://' + $('login') + ':' + $('pass') + '@mydomain.tld';">
    <input type="text" name="login" id="login" />
    <input type="password" name="pass" id="pass" />
    <input type="submit" value="ok"/>
</form>

where $() is a document.getElementById or jquery or so. I used the $() function to make the code shorter. Here is an implementation, which does not work on every browser. Again, look throw jQuery for cross browser solution.

function $(_id) { return document.getElementById(_id); }

Otherwise, you can use php and redirect the user with a header location.

php way:

<?php

if (isset($_POST['login']) && isset($_POST['password'])) { header('Location: ' . urlencode($_POST['login']) . ':' . urlencode($_POST['password']) . '@domain.tld'); }
else
{
?>
<form method="post" onsubmit="javascript:document.location='http://' + $('login') + ':' + $('pass') + '@mydomain.tld';">
    <input type="text" name="login" id="login" />
    <input type="password" name="pass" id="pass" />
    <input type="submit" value="ok"/>
</form>

<?php
}

这篇关于Http基本身份验证的登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆