日期:2010-10-17  浏览次数:20609 次

<?PHP require( "session.inc.PHP3");
require("cookie.inc.PHP3");
?>

<?PHP
   session_checkid( 20 ); //20分钟后session失效
    //下面你需要设置mysql的连接参数
    mysql_connect('localhost','user','pass') or Die("can't connect to db!");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<head>
<title>Session/Cookie-测试</title>
</head>
<body>
<h2>This Page should show how to handle the "session.inc.PHP3" library</h2>
<h3>We will use a mask with a record showing routine</h3>
<?PHP
if( $show ) {
    if( session_read() ) {
        $username = $session[username];
        $userpass = $session[userpass];
        echo "<P>session[username]:$username<br>session[userpass]:$userpass";
    }
}
else{
    $session[username]="yourid";
    $session[userpass]="12345";
    if( !session_write() ) {
        print $sess_error;
    }else{
        echo "<p>session[username]被设置成:$session[username]<br>" ;
        echo "session[userpass]被设置成:$session[userpass]<br>" ;
        echo "<a href='$PATH_INFO?show=1'>测试一下SESSION的作用</a>" ;
    }
}
?>

</body>
</HTML>