如何使php应用程序需要智能卡身份验证

Mar*_*ala 5 php smartcard

当php文件在apache conf中使用SSLVerifyClient保护时,我可以使浏览器强制使用智能卡进行身份验证,例如ID卡.

现在我需要显示index.php而不需要智能卡身份验证,有时这个页面必须得到用户身份验证.

doStuff();
if ($needed==1)
  authenticateUser();
doMoreStuff();
Run Code Online (Sandbox Code Playgroud)

必须authenticateUser()包含什么,以便调用它会导致浏览器询问智能卡密码?

Mar*_*urz 4

你把这些东西混合了一点点。
authenticateUser();运行在服务器上,而身份验证发生在客户端上。您不能在运行用于客户端身份验证的 PHP 脚本的过程中停止,然后继续运行 PHP 脚本。

作为您问题的解决方案,这可能适用于您的情况:

if(authenticationNeeded)
{
   // redirect to a page that requires authentication that does what index was supposed to do.
   redirect('index_ssl.php');
}
Run Code Online (Sandbox Code Playgroud)

通过使用,.htaccess您可以SSLVerifyClient require仅定义某些目录/文件。
关键点是:您的 Web 服务器(在本例中为 Apache)需要客户端证书才能授予对您指定的任何目录/文件的访问权限SSLVerifyClient require

结论是,没有办法做你想做的事。您只能拥有需要或不需要客户端证书的文件/目录。无法在 PHP 文件中间停止以请求客户端证书,但您可以重定向到需要客户端证书的文件。