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 &copy; 2012-2013 PHP&MySQL v1.1";
?>为什么显示会这样??

解决方案 »

  1.   

    好奇怪的输出,为什么header与footer调转了?麻烦各位大大帮一下忙吧。。这个问题闲扰了我几天了
      

  2.   

    我到是不知道你的验证码是怎么生成和显示的,和你说说我做的一个验证码的办法吧。我是建了个验证码图片生成的PHP文件t.php,这个PHP会生成一张固定大小的图片,然后随机生成字母和数字,我当时也是图片显示不出来,加了ob_clean();这一句在开头后,就没问题了,至于原因是啥,当时也测试过几次,error_reporting(E_ALL & ~(E_STRICT|E_NOTICE));加上这句后好像到是没啥问题了。具体还得测试,t.php能正常显示验证码图片了,在正常的登录页里,用了<img src = "./t.php" />就可以显示出来了。
    现详细的过滤与限制就自己玩吧。
      

  3.   


    据我的经验 验证码header前是不允许有输出的 图片显示不出来可能是因为系统有notice的报错
      

  4.   

    你好猛,这次多地方写绝对路径,要是wamp地址换了或者是你做的需要部署到服务器了咋办,难道每个绝对地址都去改??
      

  5.   


    呃谢谢你了,不过我想问的是为什么header和footer的页面会像图片那样?按道理不是copyright和当前时间都显示在footer的吗?怎么header也有copyright?
      

  6.   

    不是调转了,而是重复输出了
    你可以在浏览器中“查看网页源代码”看到这一点
    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');
      

  7.   

    楼主 可否交个朋友?我也正在学习PHP
      

  8.   


    验证码的生成:
    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);
      

  9.   


    我用的是网上下载的securimages
      

  10.   

    楼主 是出现了两次footer吧
      

  11.   

    把smartyconfig中的header,footer去掉再试