In this paper, an example of thinkphp implementation will be stored in the MySQL method, the operating environment is ThinkPHP3.1.2 version
First set in index.php to:
<?php
define (' App_debug ', true);//set to debug mode
require ' ... /thinkphp/thinkphp.php '//Set Portal file
ini_set ("Session.save_handler", "user");/set PHP session by user-defined
Set in config.php to:
<?php return Array (///
' config item ' => ' config value '
////Add Database Configuration Letter
' Show_page_trace ' =>true,
' db_type ' = > ' mysql ',//database type
' db_host ' => ' localhost ',//server address
' db_name ' => ' thinkphp ',//database name c15/> ' db_user ' => ' your username ',//username
' db_pwd ' => ' your password ',//password
' db_port ' => 3306,//Port c21/> ' Db_prefix ' => ' think_ ',//database table prefix suffix
' session_options ' =>array (
' type ' => ' DB ',// Session using the database to save
' expire ' =>1440,//session expiration time, if not set is the default value of PHP.ini
,
' session_table ' => ' Think_session ',//must be set to this, if no prefix can not find the data table, this needs attention
);
? >
The database setup takes the DDL in SessionDb.class.php, but the Engine=myisam DEFAULT Charset=utf8 is appended
CREATE TABLE think_session (
session_id varchar (255) NOT NULL,
Session_expire int (one) not NULL,
session_ Data blob,
UNIQUE KEY ' session_id ' (' session_id ')
) Engine=myisam DEFAULT Charset=utf8;
Now visit your index.php and then find the Think_session table in phpMyAdmin, we will be pleasantly surprised to find a lot of data.
This problem is settled. Other do not set, SessionDb.class.php will automatically load.
So the thinkphp call
Session (' Session_name ', ' Session_value ')
The system automatically stores this session in the database created above.