我尝试将 TOTP PHP 库作为登录表单的另一种身份验证。我从 github 下载并按照安装说明进行操作如以下代码:
<?php
include('src/Factory.php');
include('src/HOTP.php');
include('src/HOTPInterface.php');
include('src/OTP.php');
include('src/OTPInterface.php');
include('src/ParameterTrait.php');
include('src/TOTP.php');
include('src/TOTPInterface.php');
use OTPHP\TOTP;
$otp = TOTP::create();
echo 'The current OTP is: '.$otp->now();
?>
然而,我最终得到了错误消息 Warning: Unsupported declare 'strict_types' in C:\wamp64\www\otp\src\HOTP.php on line 3
和 Parse error:语法错误,意外的“?”,在第 28 行的 C:\wamp64\www\otp\src\HOTP.php 中需要变量 (T_VARIABLE)
。
我想不通为什么会这样。非常感谢您的帮助。谢谢。
最佳答案
安装较低版本的包,如 ~8.0,它适用于 PHP 5.5
https://github.com/Spomky-Labs/otphp/blob/v8.3.2/composer.json#L19
将它添加到你的 composer.json 中
“要求”:{
“spomky-labs/otphp”:“~8.3”
}
或者使用此链接将其下载为 ZIP 文件并手动将其添加到您的项目中
https://github.com/Spomky-Labs/otphp/archive/v8.3.2.zip
更好的是使用 Composer ,因为你有自动加载器。 :) 这样就不需要手动要求文件了。
关于php - 如何在 PHP 中使用 TOTP/HOTP 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44334745/