国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Mysql存取session實例

瀏覽:6日期:2023-10-26 18:17:59

files:common/Common.config.phpinclude/session.inc.phpsession_test.phpget_session_test.phpget_session_test2.php

Common.config.php <?php/** Common config* By 戀太后天*/

/** Database config*/define( 'DBTYPE', 'mysql' );$database = array( 'mysql' => array ( 'default' => array ( 'host';;=> 'localhost', 'user';;=> 'root', 'password' => '', 'dbname'=> '' ), 'session' => array ( 'host';;=> 'localhost', 'user';;=> 'session', 'password' => 'session', 'dbname'=> 'sessions' ) ));

?>

session.inc.php

<?php//使用mysql存放session 函數表// by 戀太后天 2005-4-28

if (!isset($include_path)) $include_path = '';

if (!is_array($database)){ include ($include_path.'common/Common.config.php');}

$DBsess;;;= $database[DBTYPE]['session'];$DBsess_link = mysql_connect($DBsess['host'], $DBsess['user'], $DBsess['password']) or die ('Error:<em>Can not connect to Mysql server.</em>');

$SESS_LIFE = get_cfg_var('session.gc_maxlifetime');

function sess_open($path, $name){ return true;}

function sess_close(){ return true;}

function sess_read($id){ global $DBsess , $DBsess_link; mysql_select_db($DBsess['dbname']); $now = time(); $result = mysql_query('SELECT `data` FROM `sessions` WHERE `id`= '$id' AND `expiry_time` > $now', $DBsess_link);; if (list($data) = mysql_fetch_row($result)) { return $data; } return false; }

function sess_write($id, $data){ global $DBsess , $DBsess_link, $SESS_LIFE; mysql_select_db($DBsess['dbname']);

$expiry_time = time() + $SESS_LIFE;

if ( !get_magic_quotes_gpc() ) { $data = addslashes($data); }

$now = time();

$result = mysql_query('INSERT into `sessions` (`id`, `expiry_time`,; `data`)', $DBsess_link);

if ( !$result ) { $result = mysql_query('UPDATE `sessions` SET `data`='$data', `expiry_time`=$expiry_time WHERE `id` = '$id' AND `expiry_time` > $now', $DBsess_link); }

return $result;}

function sess_destroy($id){ global $DBsess , $DBsess_link; mysql_select_db($DBsess['dbname']); $query = mysql_query('DELETE FROM `session` WHERE `id`='$id''); return $query;}

function sess_gc($maxlifetime){ global $DBsess , $DBsess_link $query = mysql_query('DELETE FROM `sessions` WHERE `expiry_time` < ' . time(), $DBsess_link); return mysql_affected_rows($DBsess_link);

}

session_module_name();session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy', 'sess_gc');

?>

session_test.php <?php// test for using sessioninclude ('common/Common.config.php');include ('include/session.inc.php');

session_start();

$_SESSION['abc'] = 'A: I will be back!';$_SESSION['meto'] = 'B: Me too ';echo '<a href='http://www.intensediesel.com/bcjs/get_session_test.php'>click me</a>';

?>

get_session_test.php

<?php// test for using sessioninclude ('common/Common.config.php');include ('include/session.inc.php');

session_start();/** www.mypchelp.cn*/$_SESSION['c'] = '<br>C: I will follow U. ^0^!';print($_SESSION['abc']);print('<br>');print($_SESSION['meto']);echo '<br>'. '<a href='http://www.intensediesel.com/bcjs/get_session_test2.php'>click again</a>';

?>

get_session_test2.php

<?php//get_session_test2.php// test for using sessioninclude ('common/Common.config.php');include ('include/session.inc.php');

session_start();print($_SESSION['c']);?>

標簽: MySQL 數據庫
主站蜘蛛池模板: 绥棱县| 遵义县| 凯里市| 志丹县| 行唐县| 恩平市| 梁平县| 德州市| 富蕴县| 桂林市| 乌海市| 霸州市| 吉林市| 福泉市| 衡东县| 九龙县| 特克斯县| 鲁甸县| 滦平县| 同仁县| 泸定县| 资溪县| 页游| 梁平县| 玉树县| 梓潼县| 紫阳县| 漳平市| 博罗县| 苍梧县| 永顺县| 青河县| 元谋县| 牡丹江市| 宁阳县| 睢宁县| 庆元县| 盐源县| 凤台县| 宜宾县| 禹城市|