:::
主內容區域
2-1 index.php
<?php
session_start();
require_once 'smarty/libs/Smarty.class.php';
//實體化
$smarty = new Smarty;
//三元運算式
$name = isset($_SESSION['name']) ? htmlspecialchars($_SESSION['name'], ENT_QUOTES) : '訪客';
$group = isset($_SESSION['group']) ? $_SESSION['group'] : '';
$op = isset($_REQUEST['op']) ? htmlspecialchars($_REQUEST['op'], ENT_QUOTES) : '';
$content = '';
switch ($op) {
case 'login':
require_once "config.php";
$name = isset($_POST['name']) ? $_POST['name'] : '';
if ($admin_id == $name and $admin_pass == $_POST['pass']) {
$_SESSION['group'] = "admin";
$_SESSION['name'] = $name;
$content = "登入成功";
} elseif ($user_id == $name and $user_pass == $_POST['pass']) {
$_SESSION['group'] = "user";
$_SESSION['name'] = $name;
$content = "登入成功";
} else {
$content = "登入失敗";
}
header("location: index.php");
exit;
case 'logout':
unset($_SESSION['group']);
unset($_SESSION['name']);
header("location: index.php");
exit;
default:
# code...
break;
}
$smarty->assign('my_name', $name);
$smarty->assign('group', $group);
$smarty->assign('page_title', '活動報名系統');
$smarty->assign('content', $content);
$smarty->display('index.tpl');
1-2 templates/index.tpl