简体   繁体   English

php 会话处理最佳实践和未定义问题

[英]php session handling best practice and undefined issue

iam currently trying to build an admin panel but i have problem about handling sessions in php我目前正在尝试构建一个管理面板,但我在处理 php 中的会话时遇到问题

my code basically depends on php and ajax request so when a user load a page for example settings page first i load session's through start_session() after the verification i close the session then i route to the page that requested by the user if the page has a submit (through ajax) i have to generate token for the request and store it in the session so i have to start new session again .我的代码基本上取决于 php 和 ajax 请求,所以当用户加载一个页面例如设置页面时,我首先在验证后通过 start_session() 加载会话我关闭会话然后我路由到用户请求的页面如果页面有提交(通过ajax)我必须为请求生成令牌并将其存储在会话中,因此我必须再次启动新会话。 because when ever i open only when session at the beginning of the page and close it at the end i have an issue with multi requests (cuz of php session locking thing xx)因为当我只在页面开头的会话时打开并在最后关闭它时,我遇到了多个请求的问题(因为 php 会话锁定了 xx)

but sometime when i open multi session through different part of the page i got issue of undefined session even though it's defined但是有时当我通过页面的不同部分打开多个会话时,即使它已定义,我也会遇到未定义会话的问题

what is the best practice here to handle like this situation处理这种情况的最佳做法是什么

Good morning.早上好。

I suggest you use Cookies to store data as encrypted JSON.我建议您使用 Cookies 将数据存储为加密的 JSON。 You will need decrypt that to test privilegies, but it's normal.你需要解密它来测试权限,但这是正常的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM