简体   繁体   English

HTTP身份验证PHP

[英]HTTP Authentication PHP

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>

I got this code from php.net 我从php.net获得此代码

is it possible to set target folder(or URL), userID and password? 是否可以设置目标文件夹(或URL),用户ID和密码? I don't want to show popup login window to user 我不想向用户显示弹出式登录窗口

for example) 例如)

after line of header('HTTP/1.0 401 Unauthorized'); 标头行之后(“ HTTP / 1.0 401未经授权”);

header('URL:./target_folder/')
header('UserID:guest')
header('Password:guest')

I'm not sure about what you want, but you can pass your username and password in the URL like this : 我不确定您想要什么,但是您可以像这样在URL中传递用户名和密码:

https://username:password@www.example.com/path

It will not display any login popup. 它不会显示任何登录弹出窗口。

Doc : https://developer.mozilla.org/en-US/docs/Web/HTTP/Basic_access_authentication Doc: https : //developer.mozilla.org/zh-CN/docs/Web/HTTP/Basic_access_authentication

Be aware of the Security section 注意“安全性”部分

The BA mechanism provides no confidentiality protection for the transmitted credentials. BA机制不为传输的凭据提供机密性保护。 They are merely encoded with BASE64 in transit, but not encrypted or hashed in any way. 它们仅在传输过程中使用BASE64编码,而没有以任何方式加密或散列。 Basic Authentication is, therefore, typically used over HTTPS. 因此,基本身份验证通常通过HTTPS使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM