|
<?php |
|
|
|
header('Content-Type: text/html; charset=Shift_JIS'); |
|
// header('Content-Type: text/x-hdml; charset=Shift_JIS'); |
|
|
|
session_name('_normal'); |
|
session_start(); |
|
|
|
$host = $_SERVER['HTTP_HOST']; |
|
if ($_pos = strpos($host, ':')) |
|
{ |
|
$host = substr($host, 0, $_pos); |
|
} |
|
|
|
$is_ssl = false; |
|
if (isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS']) |
|
{ |
|
$is_ssl = true; |
|
} |
|
|
|
if (isset($_GET['mode'])) |
|
{ |
|
$mode = $_GET['mode']; |
|
if ('login' === $mode) |
|
{ |
|
$_SESSION['user_name'] = '太郎'; |
|
$sid = session_id(); |
|
if ($is_ssl) |
|
{ |
|
header('Location: http://'.$host.'/cookie.php?mode=setlogin&sid='.$sid); |
|
exit; |
|
} |
|
else |
|
{ |
|
header('Location: https://'.$host.'/cookie.php?mode=setlogin&sid='.$sid); |
|
exit; |
|
} |
|
} |
|
elseif ('logout' === $mode) |
|
{ |
|
session_destroy(); |
|
|
|
if ($is_ssl) |
|
{ |
|
header('Location: http://'.$host.'/cookie.php?mode=setlogout'); |
|
exit; |
|
} |
|
else |
|
{ |
|
header('Location: https://'.$host.'/cookie.php?mode=setlogout'); |
|
exit; |
|
} |
|
} |
|
elseif ('setlogin' === $mode) |
|
{ |
|
session_write_close(); |
|
|
|
session_id($_GET['sid']); |
|
session_start(); |
|
if ($is_ssl) |
|
{ |
|
header('Location: http://'.$host.'/cookie.php'); |
|
exit; |
|
} |
|
else |
|
{ |
|
header('Location: https://'.$host.'/cookie.php'); |
|
exit; |
|
} |
|
} |
|
elseif ('setlogout' === $mode) |
|
{ |
|
session_destroy(); |
|
|
|
if ($is_ssl) |
|
{ |
|
header('Location: http://'.$host.'/cookie.php'); |
|
exit; |
|
} |
|
else |
|
{ |
|
header('Location: https://'.$host.'/cookie.php'); |
|
exit; |
|
} |
|
} |
|
} |
|
|
|
$username = '名無し'; |
|
if (isset($_SESSION['user_name'])) |
|
{ |
|
$username = $_SESSION['user_name']; |
|
} |
|
|
|
?> |
|
<?php if (!isset($_GET['mode'])): ?> |
|
<?php echo mb_convert_encoding('ようこそ '.$username.'さん!', 'Shift-JIS', 'UTF-8') ?> <br><br> |
|
ADDR: <?php echo $_SERVER['REMOTE_ADDR']; ?><br> |
|
PORT: <?php echo $_SERVER['SERVER_PORT']; ?><br> |
|
<br> |
|
<a href="./cookie.php?mode=login">login</a><br> |
|
<a href="./cookie.php?mode=logout">logout</a><br> |
|
<?php endif; ?> |
|
<a href="./cookie.php">Reload</a><br> |
|
<br> |
|
<a href="http://<?php echo $host ?>/cookie.php">HTTP</a><br> |
|
<a href="https://<?php echo $host ?>/cookie.php">HTTPS</a><br> |
It's too complicated for understanding. You are included so much code under PHP cookies. Management is important for PHP cookies and PHP session. You need more clarification.