pc4 pc4 - 1 year ago 416
Ajax Question

Fatal error: openssl_random_pseudo_bytes

I am building a web page with login feature and I came up with this error:

Fatal error: Call to undefined function openssl_random_pseudo_bytes() in ...Users_model.php

This is a snippet of source code where it leads(line 2):

if(password_verify($password, $row->password)) {
$token = bin2hex(openssl_random_pseudo_bytes(21));
$this->insert_token_user($row->id, $token);
$res = [
'id' => $row->id,
'first_name' => $row->first_name,
'last_name' => $row->last_name,
'email' => $row->email,
'token' => $token

And this is the code where it happens in debug (line 3):

beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(email + ":" + password));
url: URL + 'user/login',
contentType: 'application/json',
type: 'GET',
success: function(data, status, response) {
error: function(xhr, status, error) {
var err = JSON.parse(xhr.responseText);

The screenshots of errors from debugger:
error 1

error 2

I am running Windows 10 x64 and MAMP 3.2.2 as localhost.
MAMP settings: php 5.6.24 , cache off.

This is what I did to try to solve the problem:

  • removed semicolon in extension=php_openssl.dll
    in this folder C:\MAMP\conf\php5.6.24\php.ini

  • and here C:\MAMP\conf\php5.6.0\php.ini

  • moved both php.ini to C:\MAMP\bin\php\php5.6.0 and C:\MAMP\bin\php\php5.6.24 folders

The reason for doing this in these two places is because Chrome extension "Wappalyzer" shows this page as PHP version 5.6.0.

error I get when I restart my PC with semicolons removed

error I get when I restart my PC with semicolons removed

pc4 pc4
Answer Source

FIXED! Switched to PHP 7.0.9 and there is no such problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download