【问题标题】:How to use TOTP / HOTP library in PHP如何在 PHP 中使用 TOTP / HOTP 库
【发布时间】:2017-06-02 17:49:18
【问题描述】:

我尝试实现 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 3Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in C:\wamp64\www\otp\src\HOTP.php on line 28

我不明白为什么会这样。非常感谢您的帮助。谢谢。

【问题讨论】:

  • 好像您在 PHP5 中使用 PHP7 功能。严格类型仅在 7+ 上支持。
  • 我当前的版本:PHP 5.6.25,我应该卸载并升级到版本7吗?
  • 是的,如果你想使用那个库。如果您拥有该库,我想您可以删除所有 PHP7 功能。但我不建议这样做。我认为升级对你来说是一个更好的解决方案。

标签: php one-time-password


【解决方案1】:

安装较低版本的包,如 ~8.0,适用于 PHP 5.5

https://github.com/Spomky-Labs/otphp/blob/v8.3.2/composer.json#L19

在你的 composer.json 中添加这个

"require": { "spomky-labs/otphp": "~8.3" }

或使用此链接将其下载为 ZIP 并手动将其添加到您的项目中

https://github.com/Spomky-Labs/otphp/archive/v8.3.2.zip

更好的是使用作曲家,因为你有自动加载器。 :) 这样就不需要手动要求文件了。

【讨论】:

  • 非常感谢 :)
【解决方案2】:

尝试使用与 PHP 5.x 兼容的 multiOTP 类 https://github.com/multiOTP/multiotp

【讨论】:

    猜你喜欢
    • 2019-01-26
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 2019-10-23
    • 2014-10-12
    • 2022-08-19
    • 1970-01-01
    • 2022-09-28
    相关资源
    最近更新 更多