0

我正在慢慢掌握 PHP,但是很难分解我的 if 语句,以便我的标题函数工作。我已经做了一些,但它们并没有像我的密码恢复文件那样涉及那么多条件。有人可以告诉我我该怎么做吗?

<?php
include ("storescripts/init.php");
logged_in_redirect();
include ("includes/overall/head.php");?>
<?php include ("includes/overall/template_header.php");?>
<div id="mainDivShort">
<h1>Recover</h1>
<div id="divBreak"></div>
<?php include ("includes/overall/column_left.php");?>
<div id="middleContent">
    <?php 
    if(isset($_GET['success']) === true && empty($_GET['success']) === true){
        ?>
    <p>Thanks, we've emailed you.</p>
    <?php
        } else {
            $mode_allowed = array('mem_password');
            if (isset($_GET['mode']) === true && in_array($_GET['mode'],  $mode_allowed) === true) {
            if(isset($_POST['mem_email']) === true && empty($_POST['mem_email']) === false) {
                if (email_exists($_POST['mem_email']) === true) {
                    recover($_GET['mode'], $_POST['mem_email']);
                    header('Location: recover.php?success');
                    exit();
                } else {
                    echo '<p>Oops, we couldn\'t find that email in the system</p>';
                }
            }
            ?>
    <form action="" method="post">
        <ul>
            <li>Please enter your email address:<br> <input type="text"
                name="mem_email">
            </li>
            <li><input type="submit" value="Recover"></li>
        </ul>
    </form>
    <?php
        } else {
            header('Location: index.php');
            exit();
        }
        }
        ?>
</div>
<?php include ("includes/overall/column_right.php");?>
</div>
<?php include ("includes/overall/template_footer.php");?>

标题语句需要在我的 include head.php 之上,因为这包括 HTML 输出。我已经尝试过缓冲,但这对我不起作用!谢谢!

4

3 回答 3

0
<?php
ob_start(); // We start the buffer
include ("storescripts/init.php");
logged_in_redirect();
include ("includes/overall/head.php");?>
<?php include ("includes/overall/template_header.php");?>
<div id="mainDivShort">
<h1>Recover</h1>
<div id="divBreak"></div>
<?php include ("includes/overall/column_left.php");?>
<div id="middleContent">
    <?php 
    if(isset($_GET['success']) === true && empty($_GET['success']) === true){
        ?>
    <p>Thanks, we've emailed you.</p>
    <?php
        } else {
            $mode_allowed = array('mem_password');
            if (isset($_GET['mode']) === true && in_array($_GET['mode'],  $mode_allowed) === true) {
            if(isset($_POST['mem_email']) === true && empty($_POST['mem_email']) === false) {
                if (email_exists($_POST['mem_email']) === true) {
                    ob_clean(); // Clean the buffer and make the redirect
                    recover($_GET['mode'], $_POST['mem_email']);
                    header('Location: recover.php?success');
                    exit();
                } else {
                    echo '<p>Oops, we couldn\'t find that email in the system</p>';
                }
            }
            ?>
    <form action="" method="post">
        <ul>
            <li>Please enter your email address:<br> <input type="text"
                name="mem_email">
            </li>
            <li><input type="submit" value="Recover"></li>
        </ul>
    </form>
    <?php
        } else {
            ob_clean();// Clean the buffer and make the redirect
            header('Location: index.php');
            exit();
        }
        }
        ?>
</div>
<?php include ("includes/overall/column_right.php");?>
</div>
<?php include ("includes/overall/template_footer.php");?>
于 2013-03-01T14:16:40.407 回答
0
<?php
$msg = "";    
if (!empty($_GET)) //check if form has been submitted
{  
   if(isset($_GET['success']) === true && empty($_GET['success']) === true)
   {
      $msg = "Thanks, we've emailed you.";
   } 
   else 
   {
      $mode_allowed = array('mem_password');
      if (isset($_GET['mode']) === true && in_array($_GET['mode'],  $mode_allowed) === true) 
      {
         if(isset($_POST['mem_email']) === true && empty($_POST['mem_email']) === false) 
         {
            if (email_exists($_POST['mem_email']) === true) 
            {
              recover($_GET['mode'], $_POST['mem_email']);
              header('Location: recover.php?success');
              exit();
            } 
            else 
            {
              $msg = "<p>Oops, we couldn\'t find that email in the system</p>";
            }
         }
      } 
      else 
      {
         header('Location: index.php');
         exit();
      }
   }
}

include 'storescripts/init.php';
logged_in_redirect();
include 'includes/overall/head.php';
include 'includes/overall/template_header.php';
 ?>
<div id="mainDivShort">
<h1>Recover</h1>
<div id="divBreak"></div>
<?php include ("includes/overall/column_left.php");?>
<div id="middleContent">
<?php echo $msg; ?>
<form action="" method="post">
    <ul>
        <li>Please enter your email address:<br> <input type="text"
            name="mem_email">
        </li>
        <li><input type="submit" value="Recover"></li>
    </ul>
</form>
</div>
<?php include ("includes/overall/column_right.php");?>
</div>
<?php include ("includes/overall/template_footer.php");?>

你不是已经在这里解决了吗?重新排列 PHP 页面,使标题位于 HTML 之前

于 2013-03-01T14:07:20.590 回答
0

您可能不知道的是,一旦第一个字符被回显出来,php 就会发送一个标题......第一个字符甚至可以是空格,如 lf 或 tab 或 cr。等等

一旦第一个标头消失,您计划发送的其他标头将不再计算在内......因此,您混合使用文本 html 和使用标签可能会伤害您。因为 php 标记之外的第一位空白将生成一个标题,并且您计划的标题将不再计算在内。

我可以更进一步,建议您开始使用模板系统将代码与内容分开。

于 2013-03-01T14:36:29.627 回答