国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

Mysql存取session實例

2019-11-18 19:21:24
字體:
供稿:網(wǎng)友

files:
common/Common.config.php
include/session.inc.php
session_test.php
get_session_test.php
get_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 函數(shù)表
// 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 session
include ("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=/"get_session_test.php/">click me</a>";

?>

get_session_test.php


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

session_start();
/*
* www.survivalescaperooms.com
*/
$_SESSION["c"] = "<br>C: I will follow U. ^0^!";
     "<a href=/"get_session_test2.php/">click again</a>";

?>


get_session_test2.php

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

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


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 富川| 宜州市| 大荔县| 神农架林区| 临猗县| 勐海县| 盐山县| 福建省| 金乡县| 临朐县| 莱芜市| 长岭县| 正安县| 石林| 格尔木市| 西城区| 梓潼县| 宁德市| 张家港市| 宁城县| 岳西县| 同仁县| 信宜市| 西藏| 赤峰市| 宣化县| 承德市| 武清区| 金平| 新安县| 马山县| 鄂伦春自治旗| 盐边县| 布拖县| 寻乌县| 色达县| 新河县| 潜江市| 宜君县| 通渭县| 富川|