PHP:将Libsodium安装到PHP v5.5 [英] PHP: Installing Libsodium to PHP v5.5

查看:1014
本文介绍了PHP:将Libsodium安装到PHP v5.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PHP Verson 5.5正确安装Libsodium. 我正在尝试按照 https:/上的说明进行操作/paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-libsodium

How to correctly install Libsodium with PHP verson 5.5. I'm trying to follow the instruction on https://paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-libsodium

这是我执行的步骤:

  1. 转到 http://windows.php .net/downloads/pecl/releases/libsodium/1.0.6/

下载"php_libsodium-1.0.6-5.5-nts-vc11-x64.zip"并解压缩文件.

Download "php_libsodium-1.0.6-5.5-nts-vc11-x64.zip" and extract files.

将"libsodium.dll"复制到我的目录"C:\ Program Files(x86)\ PHP \ v5.5"中,其中"php.exe"

Copy "libsodium.dll" in my directory "C:\Program Files (x86)\PHP\v5.5" where is "php.exe"

在我的目录"C:\ Program Files(x86)\ PHP \ v5.5 \ ext"中复制"php_libsodium.dll"

Copy "php_libsodium.dll" in my directory "C:\Program Files (x86)\PHP\v5.5\ext"

在php.ini文件中启用"extension = php_libsodium.dll"

Enable "extension=php_libsodium.dll" in php.ini file

重新启动服务器

但是当我通过编写一个简单的PHP测试文件进行测试时:

But when I tested it by writing a simple PHP test file:

<?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() 第7行的C:\ PHP \ testLibsodium.php

Fatal error: Call to undefined function sodium_crypto_pwhash_str() in C:\PHP\testLibsodium.php on line 7

似乎未安装库Libsodium,因为它不知道该功能. 在PHP 5.5版中安装PHP Libsodium需要做些什么? 非常感谢.

The library Libsodium seems not installed because it doesn't know the function. What things I need to do to install PHP Libsodium in PHP version 5.5? Thank you very much.

更新:我已经按照@iann的建议安装了X86版本,并运行以下代码:

Update: I've installed the X86 version as advised by @iann and run this code:

$storeInDatabase = \Sodium\crypto_pwhash_str(
        "safasfdwr32sfdfas234",
        SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
        SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
        );

现在似乎正在读取该函数,但出现错误:

Now seems the function is being read but I'm getting an error:

注意:使用未定义的常量 SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE-假定 'SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE'

Notice: Use of undefined constant SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE - assumed 'SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE'

注意:使用未定义的常量 SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE-假定 'SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE'

Notice: Use of undefined constant SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE - assumed 'SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE'

警告:Sodium \ crypto_pwhash_str()期望参数2较长

Warning: Sodium\crypto_pwhash_str() expects parameter 2 to be long

可捕获的致命错误:crypto_pwhash_str():无效的参数

Catchable fatal error: crypto_pwhash_str(): invalid parameters

这是否意味着我的libsodium已正确安装,但是为什么会出现错误?再次谢谢你.

Does this mean that my libsodium is installed correctly, but why I'm getting an error? Thank you again.

推荐答案

在将库移入7.2版本机PHP之前,sodium_*函数不在全局命名空间中.来自手册:

The sodium_* functions weren't in the global namespace until the library was moved into native PHP, in version 7.2. From the manual:

在PHP 7.2之前的PECL中带有libsodium的情况下,以下函数在Sodium名称空间中定义.在PHP 7.2中,名称空间被删除,取而代之的是sodium_前缀(以符合PHP内部开发标准).

In PHP before 7.2 with libsodium from PECL, the functions below were defined in the Sodium name space. In PHP 7.2, the namespaces were dropped in favor of a sodium_ prefix (to conform to the PHP internal development standards).

因此,如果要从PECL安装,则需要使用以前的函数名称.就您而言:

So if you're installing from PECL, you need to use the previous function names. In your case:

$hash_str = \Sodium\crypto_pwhash_str(
...

这篇关于PHP:将Libsodium安装到PHP v5.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆