Session Technique of PHP programs

Session is useful to build web applications what needs login.example SNS,Shopping cart and Closed applications is used by a few users. It gives unique id for users, They use that. Usually effective things is repetition login and protect from unknown user can login.
I`ve been writing program for in-house service since last month. To check what employee stay his seat.I developed by PHP. Then I learnt Session. This article is about simple programs.

To learn how to use Session. you would not need something. because PHP is support it.

a.php

<?php
session_start();

$user_name = $_POST["name"];
if(isset($user_name){
$_SESSION['user'] = $user_name;
}else{
header("Location: http://yahoo.co.jp");
exit();
}
?>

<html>
<body>
<?php
echo("ようこそ".$user_name."さん");
?>
<p>今の状態は?</p>
<form method="POST" action="b.php">
<div id="a1">社内:<input type="checkbox" name="status" value="in"></div>
<div id="a2">社外:<input type="checkbox" name="status" value="out"></div>
</form>
</body>
</html>

b.php

<?php
session_start();

if($_SESSION['user']){
$user_name = $_SESSION['user'];
}else{
header("Location: http://yahoo.co.jp");
exit();
}

$user_status = $_POST["status"];
echo($user_name."さんは".$user_status."です");
?>

This program is simple. But actually, it connect MySQL and record personal status realtime. I will keep on develops because Now it is not yet complete.