如何使用PHP Verson 5.5正确安装libsodium。我正在尝试遵循https://paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-libsodium
这是我所做的步骤:
-
转到http://windows.php.net/downloads/pecl/releases/libsodium/1.0.6/
-
下载" php_libsodium-1.0.6-5.5-nts-vc11-x64.zip"并提取文件。
-
在我的目录中复制" libodium.dll" c: program文件(x86( php v5.5",其中" php.exe"
-
在我的目录中复制" php_libsodium.dll" c: program文件(x86( php v5.5 ext"
-
启用" extension = php_libsodium.dll" php.ini文件
-
重新启动服务器
但是,当我通过编写一个简单的PHP测试文件进行测试时:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
// hash the password and return an ASCII string suitable for storage
$hash_str = sodium_crypto_pwhash_str(
"mypassword",
SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
);
echo "hash: " . $hash_str;
?>
结果页面显示错误:
致命错误:致电未定义的功能sodium_crypto_pwhash_str(( C: php testlibsodium.php在第7行
上
图书馆libsodium似乎没有安装,因为它不知道该功能。在PHP 5.5版中安装PHP libsodium我需要做什么?非常感谢。
更新:我已经按照@iann的建议安装了X86版本,并运行此代码:
$storeInDatabase = Sodiumcrypto_pwhash_str(
"safasfdwr32sfdfas234",
SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
);
现在看来该功能正在读取,但我会遇到错误:
注意:使用未定义常数 sodium_crypto_pwhash_opslimit_interactive-假定 'Sodium_crypto_pwhash_opslimit_interactive'
注意:使用未定义常数 sodium_crypto_pwhash_memlimit_interactive-假定 'Sodium_crypto_pwhash_memlimit_interactive'
警告:钠 crypto_pwhash_str((期望参数2长
可收集的致命错误:crypto_pwhash_str((:无效参数
这是否意味着我的libsodium已正确安装,但是为什么我会遇到错误?再次感谢您。
sodium_*
函数在全局名称空间中不在全局名称空间中,直到库中的7.2版将库移至本机PHP中。从手册中:
在7.2之前使用PECL的libsodium之前的PHP中,以下功能在钠名空间中定义。在PHP 7.2中,将命名空间放下以钠_前缀(符合PHP内部发展标准(。
。
因此,如果您是从PECL安装的,则需要使用以前的功能名称。在您的情况下:
$hash_str = Sodiumcrypto_pwhash_str(
...