サーバーは、リクエストがあったクライアントに対し、セッションIDを出してクライアント側に保存させる。サーバーはセッションIDとクライアントのやりとりを保存。
次回、クライアントがサーバーに接続した際に、記録を引き継ぐことができる。
クッキーは、クライアント側で情報を保存する。
example
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <html> <head> <title>空売り機関投資家</title> </head> <body> 機関投資家 <form action= "regist.php" method= "post" > <table> <tr> <td><input type= "text" name= "investor" ></td> <td> <input type= "submit" value= "登録" > </td> </tr> </table> </body> </html> |
regist.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php session_start(); ?> <html> <head> <title>登録画面</title> </head> <body> <?php $investor = $_POST [ 'investor' ]; $_SESSION [ 'investor' ] = $_POST [ 'investor' ]; print ( "次の機関投資家を登録しました<br>" ); print ( "機関投資家: $investor<br>" ); ?> <a href= "regist_check.php" >確認</a> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <? session_start(); ?> <html> <head> <title>登録画面</title> </head> <body> <?php print ( "登録済み:<br>" ); print ( $_SESSION [ 'investor' ]. "<br>" ); ?> <a href= "index.php" >追加登録</a> </body> </html> |