5

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!

jww
  • 97,681
  • 90
  • 411
  • 885
marius
  • 163
  • 1
  • 2
  • 16
  • 2
    Check your error logs and your PHP modules paths. Just because you're telling PHP to load the sessions extension doesn't mean that it actually exists on your machine. – WWW Dec 11 '14 at 17:04
  • 2
    You might also run [`phpinfo()`](http://php.net/manual/en/function.phpinfo.php) to see whether the module is loaded properly. – GolezTrol Dec 11 '14 at 17:06
  • check phpinfo() or php -i – Nick Dec 11 '14 at 17:06
  • Someone might be a php newbie like me so I'm putting this in. I checked phpinfo and session support was enabled. Problem was that I wrote `session.start();` instead of `session_start();`. I think I'm allowed to simply say "doesn't work" for this one. – BobRodes May 16 '16 at 04:50

4 Answers4

10

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
vladkras
  • 16,483
  • 4
  • 45
  • 55
  • 2
    Did alpine rename their package manager, or is that a typo? https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management v https://openwrt.org/docs/guide-user/additional-software/opkg – AD7six Jun 09 '21 at 14:03
  • I'm using PHP 8 on Alpine, and added the following to my Dockerfile: `apk add php8-session` Seems to be working OK. Thanks for the suggestion @vladkras – dougB Oct 14 '22 at 02:49
3

On FreeBSD 11:

su pkg install php72-session
service php-fpm restart

my 2 cents

Code4R7
  • 2,600
  • 1
  • 19
  • 42
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

vp_arth
  • 14,461
  • 4
  • 37
  • 66
2

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.

mlemos
  • 1,235
  • 13
  • 21