smarty:contents-template.tpl:{include file="D:/xampp/php/Smarty/demo/templates/header.tpl"}{$contents}{include file="D:/xampp/php/Smarty/demo/templates/footer.tpl"}
header.tpl:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>{$pageTitle}</title>
<script type="text/javascript" defer="defer" src="/MyProject/Javascript/showTime.js"></script>
<link rel="stylesheet" type="text/css" href="CSS/CSS.css"/>
</head><body>
<noscript>不能显示javascript</noscript>
<hr />
footer.tpl: <hr />
<div align="center">{$copyright}</div>
<div id="showTime" align="center"></div>
</body>
</html>
登录页面php:<?php
include 'CommonLibraries/common.php';
require 'CommonLibraries/smartyConfig.php';
session_start();
header('Cache-control: private'); ob_start();
include 'pages/login-template.php';
$loginForm = ob_get_clean();
if (isset($_POST['Login'])) {
if (isset($_POST['loginUserName']) && (trim($_POST['loginUserName']) != '') &&
isset($_POST['loginUserPassword']) && ($_POST['loginUserPassword'] != '')) {
$_SESSION['SUBMIT_LOGIN'] = true;
$_SESSION['LOGIN_USERNAME'] = trim($_POST['loginUserName']);
$_SESSION['LOGIN_USERPASSWORD'] = $_POST['loginUserPassword'];
header('Location: php/login-process.php');
}
else {
$errorMessgeForm = '<p><strong>请输入你的'.((($_POST['loginUserName'] == '') && ($_POST['loginUserPassword'] == '')) ? '用户名与密码' :
(($_POST['loginUserName'] == '') ? '用户名' : '密码')).'!</strong></p>';
$loginForm = $errorMessgeForm . $loginForm;
}
}
$smarty->assign('contents', $loginForm);
$smarty->display('contents-template.tpl');
?>
smartyConfig.php:<?php
require_once 'D:/xampp/php/Smarty/libs/Smarty.class.php';
include_once 'template-config.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";
$smarty->assign('pageTitle', $TEMPLATE['pageTitle']);
$smarty->display('header.tpl');
$smarty->assign('copyright', $TEMPLATE['copyright']);
$smarty->display('footer.tpl');
?>
template-config.php:<?php
$TEMPLATE['pageTitle'] = '我的作品';
$TEMPLATE['copyright'] = "Copyright © 2012-2013 PHP&MySQL v1.1";
?>为什么显示会这样??
header.tpl:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>{$pageTitle}</title>
<script type="text/javascript" defer="defer" src="/MyProject/Javascript/showTime.js"></script>
<link rel="stylesheet" type="text/css" href="CSS/CSS.css"/>
</head><body>
<noscript>不能显示javascript</noscript>
<hr />
footer.tpl: <hr />
<div align="center">{$copyright}</div>
<div id="showTime" align="center"></div>
</body>
</html>
登录页面php:<?php
include 'CommonLibraries/common.php';
require 'CommonLibraries/smartyConfig.php';
session_start();
header('Cache-control: private'); ob_start();
include 'pages/login-template.php';
$loginForm = ob_get_clean();
if (isset($_POST['Login'])) {
if (isset($_POST['loginUserName']) && (trim($_POST['loginUserName']) != '') &&
isset($_POST['loginUserPassword']) && ($_POST['loginUserPassword'] != '')) {
$_SESSION['SUBMIT_LOGIN'] = true;
$_SESSION['LOGIN_USERNAME'] = trim($_POST['loginUserName']);
$_SESSION['LOGIN_USERPASSWORD'] = $_POST['loginUserPassword'];
header('Location: php/login-process.php');
}
else {
$errorMessgeForm = '<p><strong>请输入你的'.((($_POST['loginUserName'] == '') && ($_POST['loginUserPassword'] == '')) ? '用户名与密码' :
(($_POST['loginUserName'] == '') ? '用户名' : '密码')).'!</strong></p>';
$loginForm = $errorMessgeForm . $loginForm;
}
}
$smarty->assign('contents', $loginForm);
$smarty->display('contents-template.tpl');
?>
smartyConfig.php:<?php
require_once 'D:/xampp/php/Smarty/libs/Smarty.class.php';
include_once 'template-config.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";
$smarty->assign('pageTitle', $TEMPLATE['pageTitle']);
$smarty->display('header.tpl');
$smarty->assign('copyright', $TEMPLATE['copyright']);
$smarty->display('footer.tpl');
?>
template-config.php:<?php
$TEMPLATE['pageTitle'] = '我的作品';
$TEMPLATE['copyright'] = "Copyright © 2012-2013 PHP&MySQL v1.1";
?>为什么显示会这样??
现详细的过滤与限制就自己玩吧。
据我的经验 验证码header前是不允许有输出的 图片显示不出来可能是因为系统有notice的报错
呃谢谢你了,不过我想问的是为什么header和footer的页面会像图片那样?按道理不是copyright和当前时间都显示在footer的吗?怎么header也有copyright?
你可以在浏览器中“查看网页源代码”看到这一点
contents-template.tpl 中有
{include file="D:/xampp/php/Smarty/demo/templates/header.tpl"}
{$contents}
{include file="D:/xampp/php/Smarty/demo/templates/footer.tpl"}smartyConfig.php 中又有
$smarty->display('header.tpl');
$smarty->display('footer.tpl');
验证码的生成:
login-page.php:<?php
include 'CommonLibraries/common.php';
require 'CommonLibraries/smartyConfig.php';
session_start();
header('Cache-control: private'); ob_start();
include 'pages/login-template.php';
$loginForm = ob_get_clean();
if (isset($_POST['Login'])) {
if (isset($_POST['loginUserName']) && (trim($_POST['loginUserName']) != '') &&
isset($_POST['loginUserPassword']) && ($_POST['loginUserPassword'] != '')) {
$_SESSION['SUBMIT_LOGIN'] = true;
$_SESSION['LOGIN_USERNAME'] = trim($_POST['loginUserName']);
$_SESSION['LOGIN_USERPASSWORD'] = $_POST['loginUserPassword'];
header('Location: php/login-process.php');
}
else {
$errorMessgeForm = '<p><strong>请输入你的'.((($_POST['loginUserName'] == '') && ($_POST['loginUserPassword'] == '')) ? '用户名与密码' :
(($_POST['loginUserName'] == '') ? '用户名' : '密码')).'!</strong></p>';
$loginForm = $errorMessgeForm . $loginForm;
}
}
$smarty->assign('contents', $loginForm);
$smarty->display('contents-template.tpl');
?>
login-template.php:<form action="<?php htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post">
<table>
<caption>用户登录</caption>
<tr>
<td id="title">用户名</td>
<td><input type="text" name="loginUserName"
value="<?php isset($_POST['loginUserName']) ? htmlspecialchars($_POST['loginUserName']) : '';?>"/></td>
</tr>
<tr>
<td id="title">密码</td>
<td><input type="password" name="loginUserPassword" size="20"/></td>
</tr>
<tr>
<td></td>
<td><img src="../CommonLibraries/CAPTCHA/useCaptcha.php?sid=<?php echo md5(uniqid(time()));?>"/>
<a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">看不清楚,换一张验证码</a></td>
</tr>
<tr>
<td id="title">验证码</td>
<td><input type="text" name="loginCaptcha" size="6"/></td>
</tr>
<tr id="btn">
<td><input type="submit" name="Login" value="提交"/></td>
<td><input type="reset" name="Reset" value="重置"/></td>
</tr>
</table>
</form>
useCaptcha.php:<?php
require 'CommonLibraries/common.php';
require 'securimages/securimage.php';
ob_clean();
$img = new Securimage();
$img->image_width = 120;
$img->image_height = 40;
$img->perturbation = 0.85;
$img->image_bg_color = new Securimage_Color("#f6f6f6");
$img->use_transparent_text = true;
$img->text_transparency_percentage = 30;
$img->num_lines = 7;
//$img->line_color = new Securimage_Color("#eaeaea");
$img->signature_color = new Securimage_Color(rand(0, 64), rand(64, 128), rand(128, 255));
$img->use_wordlist = true;
$img->show('backgrounds/bg6.png');
?>
common.php中error_reporting(E_ALL | E_STRICT);
我用的是网上下载的securimages