【问题标题】:php header cannot redirectphp标头无法重定向
【发布时间】:2012-09-12 13:00:54
【问题描述】:

我已经实现了一个简单的注册页面,用户注册后必须将他们重定向到感谢页面,这是我的代码,它返回一个空白页面

' 保存.php '

   if($mail->Send()) {}

    unset($_SESSION['GENRE_REQUEST']);

    }
    header('Location:thanku.php');
        exit();
    }
    else
        {
        header('Location:thanku.php');
        exit();
        } '

谢谢.php

 <tr>
       <td align="center" valign="top"><b>Thank You for Registering With us.</b> <br />
        <br />please activate your profile by clicking on the activation link sent to your email address.<br/>
       </td>
  </tr> 'a
                      '

【问题讨论】:

  • 开启错误报告。并告诉错误。
  • 两件事:确保您的save.php 程序正在执行重定向发生的行,方法是在header() 调用之前放置一个die('test')。然后,通过清除所有内容并将test 文本放入其中,确保调用您的thanku.php 页面。这样,您就会知道错误发生在哪里。
  • 根据您发布的帖子,您在第一行有一个},删除最后一个
  • 如果我看到一个名为“thanku”的页面,我可能会立即离开。
  • 抱歉,这是什么? } ' 是错字吗?

标签: php redirect header


【解决方案1】:

试试,

if($mail->Send()) {
    header('Location:thanku.php');
    exit();
}else{
    echo "Oops! there was some error in sending the mail";
}

在thanku.php页面中,

<?php
    session_start();
    session_unset();
    session_destroy();
    $_SESSION = array();

    echo "Thanks message";

?>

【讨论】:

    【解决方案2】:

    查看更多代码会很有帮助。此外,如果您的 header("Location:somenewpage.php") 调用失败,php 应该会发出某种错误。您是否在 php 设置中打开了 display_errors(至少对于您的开发环境)?这将帮助您了解您的脚本出了什么问题。

    【讨论】:

      【解决方案3】:

      这样试试

      if($mail->Send()) {
         session_destroy();
         header('Location:thanku.php');
      }
      else
      {
        header('Location:thanku.php');
      }
      

      【讨论】:

      • unset() 不会完全破坏会话。
      • else { echo "发送邮件时出错";}
      猜你喜欢
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      • 2021-07-07
      相关资源
      最近更新 更多