简体   繁体   中英

PHP.ini example to enable sessions?

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 :)

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

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

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).

I guess you must increase your session as follow:

session.cookie_lifetime 0 0 and session.gc_maxlifetime 1440 1440

to

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

86400 means 1 day.

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

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

session.save_handler

You can also give sqlite db to store your session like

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

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

PHP: Runtime Configuration #session.save_path

Take a look at this page where a user describes having a similar issue.

After installing and settings, rebooting solves problem. Manually starting servers did produce the result above. Definetly somethings does not load properly when starting the server manually.

I hope still helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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