且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PHP身份验证的HTTP身份验

更新时间:2023-02-26 12:47:48

您似乎在混淆身份验证(您提供某种登录方式)和HTTP身份验证(您专门使用要进行身份验证的HTTP协议,浏览器会向用户显示一个弹出窗口。)

It seems like you are confusing authentication (where you provide some way to login) with HTTP authentication (where you specifically use the HTTP protocol to authenticate, and the browser shows a popup to the user).

您可能想要前者,这样您就可以设置登录页面的样式。在这种情况下,您将不得不使用PHP或某些脚本语言来检查用户是否已登录。 fpassthru 或者 readfile 可以成为某些网站的理想解决方案;它们是快速的,并且针对这类工作进行了优化。

You probably want the former so you can style the login page. In that case you'll have to use PHP or some scripting langauge to check that the user is logged in. fpassthru or readfile can be good solutions for some web sites; they're fast and optimised for this type of work.

如果你真的想在网络浏览器中而不是在PHP中进行文件处理工作,那么一个解决方案就是创建独特的,短命的文件名。例如,您可以使用链接在PHP中创建指向该文件的硬链接,然后将用户重定向到临时文件名。将硬链接存储在数据库中,并在一段时间后将其删除。

If you really want to do the file handling work in the web browser and not in PHP, one solution can be to create unique, short-lived filenames. You can for example create hard links to the file in PHP using link and then redirect the user to the temporary filename. Store the hard links in a database and remove them after a short while.