I'm using CentOS 6.0 Linux 64 bit with the stock packages:
# rpm -qa|grep php
php-cli-5.3.2-6.el6_0.1.x86_64
php-5.3.2-6.el6_0.1.x86_64
php-xml-5.3.2-6.el6_0.1.x86_64
php-pgsql-5.3.2-6.el6_0.1.x86_64
php-pear-1.9.0-2.el6.noarch
php-pdo-5.3.2-6.el开发者_StackOverflow6_0.1.x86_64
php-common-5.3.2-6.el6_0.1.x86_64
# rpm -qa|grep postgres
postgresql-devel-8.4.7-1.el6_0.1.x86_64
postgresql-docs-8.4.7-1.el6_0.1.x86_64
postgresql-libs-8.4.7-1.el6_0.1.x86_64
postgresql-8.4.7-1.el6_0.1.x86_64
postgresql-server-8.4.7-1.el6_0.1.x86_64
and would like to change my own PHP script from using $_SERVER['REMOTE_USER'] to using $_SESSION, but don't have any experience with PHP sessions yet.
I'd like the (quite extensive) user data to be stored into the PostgreSQL and only save a "user id" in $_SESSION.
However this doc says "This extension is considered unmaintained and dead".
Does anybody please have any advice, what to do here?
Maybe I can save session data into the db myself (and how)?
You can override PHP's session save/load handlers with your own: http://php.net/manual/en/function.session-set-save-handler.php
This lets you save the session data to a database, or chip it onto a stone tablet if you'd like. The choice of underlying storage medium/database is irrelevant, as long as your code sends/receives the session data properly.
Simple flat version :
sql("INSERT INTO sessions (session,userid) VALUES('".json_encode($_SESSION["toomuchuserinfo"])."','".$_SESSION['userid']."');");
$r=sql("SELECT session FROM sessions where userid='".$_SESSION['userid']."';");
$_SESSION["toomuchuserinfo"]=json_decode($r[0][0]);
精彩评论