login-page.php:<?php
require_once 'D:/xampp/php/Smarty/libs/Smarty.class.php'; $smarty = new Smarty();
$smarty->template_dir = "D:/xampp/php/Smarty/demo/templates";
$smarty->compile_dir = "D:/xampp/php/Smarty/demo/compile_dir";
$smarty->config_dir = "D:/xampp/php/Smarty/demo/configs";
$smarty->cache_dir = "D:/xampp/php/Smarty/demo/cache";
ob_start();
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post">
<table>
<tr>
<td>用户名</td>
<td><input type="text" name="UserName"
value="<?php isset($_POST['UserName']) ? htmlspecialchars($_POST['UserName']) : '';?>"/></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="UserPassword" size="20"/></td>
</tr>
<tr id="btn">
<td><input type="submit" name="Login" value="提交"/></td>
<td><input type="reset" name="Reset" value="重置"/></td>
</tr>
</table>
</form>
<?php
$loginForm = ob_get_clean();
if (!isset($_POST['Login'])) {
$smarty->assign('contents', $loginForm);
$smarty->display('contents-template.tpl');
}
else {
if (isset($_POST['UserName']) && isset($_POST['UserPassword'])) {
header('Location: php/login-process.php');
exit();
}
else {
$smarty->assign('contents', $loginForm);
$smarty->display('contents-template.tpl');
}
}
?>
contents-template.tpl:
{include file="D:/xampp/php/Smarty/demo/templates/header.tpl"}{$contents}{include file="D:/xampp/php/Smarty/demo/templates/footer.tpl"}为什么没有填用户名与密码直接提交却也进入php/login-process.php?
require_once 'D:/xampp/php/Smarty/libs/Smarty.class.php'; $smarty = new Smarty();
$smarty->template_dir = "D:/xampp/php/Smarty/demo/templates";
$smarty->compile_dir = "D:/xampp/php/Smarty/demo/compile_dir";
$smarty->config_dir = "D:/xampp/php/Smarty/demo/configs";
$smarty->cache_dir = "D:/xampp/php/Smarty/demo/cache";
ob_start();
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post">
<table>
<tr>
<td>用户名</td>
<td><input type="text" name="UserName"
value="<?php isset($_POST['UserName']) ? htmlspecialchars($_POST['UserName']) : '';?>"/></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="UserPassword" size="20"/></td>
</tr>
<tr id="btn">
<td><input type="submit" name="Login" value="提交"/></td>
<td><input type="reset" name="Reset" value="重置"/></td>
</tr>
</table>
</form>
<?php
$loginForm = ob_get_clean();
if (!isset($_POST['Login'])) {
$smarty->assign('contents', $loginForm);
$smarty->display('contents-template.tpl');
}
else {
if (isset($_POST['UserName']) && isset($_POST['UserPassword'])) {
header('Location: php/login-process.php');
exit();
}
else {
$smarty->assign('contents', $loginForm);
$smarty->display('contents-template.tpl');
}
}
?>
contents-template.tpl:
{include file="D:/xampp/php/Smarty/demo/templates/header.tpl"}{$contents}{include file="D:/xampp/php/Smarty/demo/templates/footer.tpl"}为什么没有填用户名与密码直接提交却也进入php/login-process.php?
header('Location: php/login-process.php');
上面来一句
print_r($_POST);exit;瞧瞧传来的数据是什么模样吧,不信再判断一下\
if($_POST['UserName']==='')echo '坑爹啊!看来要用empty函数!';