gpt4 book ai didi

PHP序列化函数-将序列化后的数据添加到mysql中,然后获取并显示

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:11 26 4
gpt4 key购买 nike

我想知道 PHP 序列化函数是否 100% 安全,另外如果我们将序列化数据存储到数据库中并想在获取它之后做一些事情,这是否是一个不错的方法。

例如:- 我有一个具有不同用户权限的网站,现在我想将特定权限的权限设置存储到我的数据库中(我要存储的数据是通过 php 序列化函数完成的),现在当用户登录我想获取此数据并为客户设置权限。

现在我可以做这件事了,我想知道的是,这是最好的方法还是可以做一些更有效率的事情。

此外,我正在浏览 php 手册并找到这段代码,任何人都可以向我解释一下这段代码中发生了什么:- [特别是为什么使用 base64_encode?]

<?php 
mySerialize( $obj ) {
return base64_encode(gzcompress(serialize($obj)));
}

myUnserialize( $txt ) {
return unserialize(gzuncompress(base64_decode($txt)));
}
?>

此外,如果有人可以向我提供他们自己的代码,让我知道如何以最有效的方式完成这件事。

我有一个问题,我有很多字段可以作为权限,现在假设我有 45 个模块供管理员使用,30 个模块供用户使用权限/权限。将来(因为我一直致力于这个项目)我将添加越来越多的模块,比如说大约 100 个,那么我将如何定义权限。甚至我正在添加一个模块来创建具有自定义权限的自定义组。我将如何实现它,同时牢记效率?请帮助:|

我不会使用序列化数据进行搜索

我的数据库:-

Database Structure

Database Content

注意:- 用户权限将通过:privileges_level 授予

注意:-在 privileges_permissions 中,我想以序列化形式添加所有权限。

谢谢。

最佳答案

Serialization can be attempted or can be a good approach to store user settings 
or preferences – you only really need to store the settings that differ from the
default values.

Serialization is good approach for just storing and getting back data
not for
searching on the serialized column or update individual value in the column.

If you want to just store and update user settings as on change and just
deserialize nothing from php and nothing to do with the values in the column
much specifically. Go for Serialization.

It can in no ways help you maintain
relationship with serialized data. The moment you require to make the data
serialized meaningful or relational. You need to
normalize.

如果应用程序确实是无模式的,并且有很多可选参数不会出现在每条记录中,那么在一列中序列化数据可能比拥有许多额外的 NULL 列更好。

This will answer your question

你需要注意:

1) 如果您不断地对非常大的 blob 中的一条数据进行小幅更新,MySQL 的工作量就会大大增加。

2) 功能损失:我认为用户设置不需要它。

关于PHP序列化函数-将序列化后的数据添加到mysql中,然后获取并显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9798949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com