首页 > 代码库 > php -- session

php -- session

----- 012-form.html -----

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>一个PHP网页</title>
</head>
<body>
<center>
    <form action="012-session.php">
        用户名:<input type="text" name="username"/><br/>&nbsp;&nbsp;码:<input type="text" name="password"/><br/>
        <input type="submit" name="submit" value="登录"/>
        <input type="reset" name="reset" value="重置"/>
    </form>
</center>
</body>
</html>

----- 012-session.php -----

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="content-type" content="text/html; charset=utf-8">
 5     <title>一个PHP网页</title>
 6 </head>
 7 <body>
 8 <?php
 9     echo "保存会话<br/>";
10     session_start();
11     $_SESSION[‘username‘] = $_GET[‘username‘];
12     $_SESSION[‘password‘] = $_GET[‘password‘];
13     echo "现在的会话内容是:<br>";
14     echo "用户名:", $_SESSION[‘username‘], "<br/>";
15     echo "密码:", $_SESSION[‘password‘], "<br/>";
16 ?>
17 </body>
18 </html>