Call to undefined function session_start()

拈花ヽ惹草 提交于 2021-01-27 05:19:09

问题


I'm trying to start a session with php, but I always get this error:

Fatal error: Call to undefined function session_start() in /www/test/test.php on line 2

My Code (Copied form http://php.net/manual/en/session.examples.basic.php):

<?php
session_start();
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
?>

In my php.ini I got extension=session.so . Further, my settings in session section are:

[Session]
session.save_handler = files
session.save_path = "/tmp"
session.use_cookies = 1
;session.cookie_secure =
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor     = 100
session.gc_maxlifetime = 1440
session.bug_compat_42 = On
session.bug_compat_warn = On
session.referer_check =
session.entropy_length = 0
;session.entropy_file = /dev/urandom
session.entropy_file =
;session.entropy_length = 16
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 4
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="

I'm using PHP Version 5.4.17. The server is running on an Arduino Yun (Linux).

Anyone can help me, or give ma a hint? :)

Thanks!


回答1:


I had to install additional php7-session package on Alpine Linux to make it work. I guess you can install it too:

opkg install php5-mod-session



回答2:


looks like self-compiled php with --disable-session for minimization purpose.
Try to recompile your php without this option.

You can check this in php -i output.
Should be Session support => enabled




回答3:


If you are running PHP cli version from a shell, the session extension is not included because it does not make sense, as sessions only exist when the user is accessing your server via a Web browser.




回答4:


On FreeBSD 11:

su pkg install php72-session
service php-fpm restart

my 2 cents



来源:https://stackoverflow.com/questions/27428424/call-to-undefined-function-session-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!