Magento 2.3.1 unserialize error
-
03-03-2021 - |
質問
In magento 2.3.1 I have this code:
public function encrypt($params)
{
return base64_encode($this->encryptor->encrypt(serialize($params)));
}
/**
* Decrypt tracking key
*
* @param string $key
* @return array
*/
public function decrypt($key)
{
$serializedParams = $this->encryptor->decrypt(base64_decode($key));
return unserialize($serializedParams);
}
It is from a module which tracks newsletters. But I get error
Notice: unserialize(): Error at offset 0 of 48 bytes in myfile.php on line 51
Which is
return unserialize($serializedParams);
Can anyone help me with the right syntax of this please?
解決
Please go here and change the code as per the below instruction.
public function encrypt($params)
{
return base64_encode($this->encryptor->encrypt(json_encode($params)));
}
/**
* Decrypt tracking key
*
* @param string $key
* @return array
*/
public function decrypt($key)
{
$serializedParams = $this->encryptor->decrypt(base64_decode($key));
return json_decode($serializedParams,true);
}
3. Please run the below command
php bin/magento c:f
所属していません magento.stackexchange