将 php.ini 的 session.auto_start 设置为 1 是否被认为是不好的做法? [英] Is setting php.ini's session.auto_start to 1 considered bad practice?

查看:26
本文介绍了将 php.ini 的 session.auto_start 设置为 1 是否被认为是不好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 php.ini 的 session.start_auto 并尝试将其设置为 1.我正在构建的站点无论如何都需要在每个页面上进行会话管理,并且服务器仅包含一个站点.这是否被认为是不好的做法(比如打开全局变量 - 我不会顺便说一句!) - php.net 对此并没有说太多.

I was playing around with php.ini's session.start_auto and tried setting it to 1. The site I am building requires session management on every page anyways and the server only contains the one site. Is this considered bad practice (like having globals turned on - which I dont BTW!) - php.net doesn't say a lot about it.

推荐答案

  • 如果部署您的应用程序的人无法控制 php.ini(例如共享主机),则依赖 php.ini 设置的 IMO 可能会很棘手.并且即使 php.ini 可以更改,由于 php.ini 配置问题导致的问题可能难以理解(您可能必须编写一个脚本允许检查配置是否正常等).

    • IMO relying on php.ini settings can be tricky if people deploying your app don't have control on the php.ini (e.g. shared hosting). And even if the php.ini can be changed, understanding a problem due to a php.ini configuration problem may be difficult to understand (you may have to write a script allowing to check if config is Ok, etc.).

      作为替代方案,您可以创建一个独特的控制器"脚本(例如 /index.php),它将根据发送给它的参数(例如 yoursite.com/index.php?page=12 甚至更好的 yoursite.com/page/12 路由和 URL 重写).在该 index.php 文件中,为所有页面放置一次 session_start().

      As an alternative, you can create a unique "controller" script (e.g. /index.php), which will call and output different pages depending on parameters sent to it (e.g. yoursite.com/index.php?page=12 or even better yoursite.com/page/12 with routing & URL rewriting). And in that index.php file, put your session_start() once for all pages.

      这篇关于将 php.ini 的 session.auto_start 设置为 1 是否被认为是不好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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