Login Form For Http Basic Auth

前端 未结 4 694
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 14:53

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

4条回答
  •  一向
    一向 (楼主)
    2020-12-17 15:17

    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:

    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:

    
    

提交回复
热议问题