PHP session By default is stored in the server side of the file, and in the client using cookies to save variables, this will be a problem, when a user for some security reasons to shut down the browser's cookies, the program's session-related operations will not be able to execute. Therefore, if you can save session data in a database, you will not be limited by the client settings and have a leap in performance and scalability. The key function in the program is Session_set_save_handler, while the Session.save_handler = files in php.ini are changed to user. The environment we are discussing here is the Linux (FREESD) +apache+mysql+php.
Datasheet structure: [Sessions]
CREATE TABLE Sessions (
Sesskey char (not NULL),
expiry int (one) unsigned NOT NULL,
Value text NOT NULL,
PRIMARY KEY (Sesskey)
);
Program code: [session_inc.php]
<?php
$SESS _dbhost = "Yourhost"; /* Database Server hostname * *
$SESS _dbname = "Yourdb"; /* Database name */
$SESS _dbuser = "Youruser"; /* Database user */
$SESS _dbpass = "YourPassword"; /* Database Password * *
After completing the steps, use require ("session_inc.php") in the program instead of Session_Start (), and the other session functions are called as before.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.