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");?>

これには HTML 出力が含まれるため、ヘッダー ステートメントは my includes head.php の上にある必要があります。バッファリングを試しましたが、うまくいきませんでした! ありがとうございました!

4

3 に答える 3

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");?>

すでにここでこれを解決しませんでしたか?ヘッダーがHTMLの前になるようにPHPページを再配置

于 2013-03-01T14:07:20.590 に答える
0

あなたが気付いていないかもしれないのは、最初の文字がエコーアウトされるとすぐにphpがヘッダーを送信するということです...その最初の文字は、lf、tab、crのような空白にすることもできます。等

その最初のヘッダーがなくなると、送信する予定の他のヘッダーはカウントされなくなります...したがって、テキストhtmlの混合とタグの使用はおそらくあなたを傷つけるでしょう。phpタグの外側の空白の最初のビットがヘッダーを生成し、計画されたヘッダーはカウントされなくなるためです。

さらに進んで、テンプレートシステムを使用してコードをコンテンツから分離することをお勧めします。

于 2013-03-01T14:36:29.627 に答える
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 に答える