启用会话的 PHP.ini 示例?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16705786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:34:10  来源:igfitidea点击:

PHP.ini example to enable sessions?

php

提问by Warren

PHP newbie here, but I can't find a straight answer online. Given the bellow session section of my phpinfo, what would I need in a php.ini to enable sessions in the most basic of ways? Thanks :)

PHP 新手在这里,但我在网上找不到直接的答案。鉴于我的 phpinfo 的波纹管会话部分,我需要在 php.ini 中以最基本的方式启用会话吗?谢谢 :)

Session Support enabled
Registered save handlers    files user
Registered serializer handlers  php php_binary wddx

Directive   Local Value Master Value
session.auto_start  Off Off
session.bug_compat_42   On  On
session.bug_compat_warn On  On
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly Off Off
session.cookie_lifetime 0   0
session.cookie_path /   /
session.cookie_secure   Off Off
session.entropy_file    no value    no value
session.entropy_length  0   0
session.gc_divisor  100 100
session.gc_maxlifetime  1440    1440
session.gc_probability  1   1
session.hash_bits_per_character 4   4
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   no value    no value
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0

回答by Burhan Khalid

PHP installations do not need any special configuration to enable sessions. They are enabled by default.

PHP 安装不需要任何特殊配置来启用会话。默认情况下它们是启用的

You should make sure you have session_start();as the first line in any page that you intend to use sessions; it should be the very first line, before any whitespace (an empty line, for example).

您应该确保session_start();您打算使用会话的任何页面的第一行;它应该是第一行,在任何空格之前(例如空行)。

回答by chandresh_cool

There are a following built-in options for storing session data. The session handler is set in the php.ini under the directive named

有以下用于存储会话数据的内置选项。会话处理程序在名为的指令下的 php.ini 中设置

session.save_handler

You can also give sqlite db to store your session like

您还可以使用 sqlite db 来存储您的会话,例如

session.save_handler = sqlite
session.save_path = /tmp/phpsess.db

回答by SomeShinyObject

Your current save_handleris set to store session date in files on the system. The problem is that your save_pathlooks like it doesn't currently have a value. You will need to add a save_pathso PHP knows where to put those files.

您当前save_handler设置为将会话日期存储在系统上的文件中。问题是你save_path看起来它目前没有价值。您需要添加一个,save_path以便 PHP 知道将这些文件放在哪里。

PHP: Runtime Configuration #session.save_path

PHP:运行时配置#session.save_path

Take a look at this pagewhere a user describes having a similar issue.

看看这个页面,用户描述了一个类似的问题。

回答by Adarsh Khatri

I guess you must increase your session as follow:

我想你必须增加你的会话如下:

session.cookie_lifetime 0 0and session.gc_maxlifetime 1440 1440

session.cookie_lifetime 0 0session.gc_maxlifetime 1440 1440

to

session.cookie_lifetime 86400 86400and session.gc_maxlifetime 86400 86400cumulatively.

session.cookie_lifetime 86400 86400session.gc_maxlifetime 86400 86400累积。

86400 means 1 day.

86400 表示 1 天。

This will allow your system to use "session_start()" which will have 1 day life. Hope this helps someone.

这将允许您的系统使用具有 1 天寿命的“session_start()”。希望这可以帮助某人。