duangua6912 2011-06-03 20:21
浏览 36

表单成功后php重定向

Using php script to allow people to add their email to a mailing list. When it successfully writes the email to the .txt doc it displays a success message on a white page. I want it to redirect to a page I've designed to look like the rest of the site. I've read elsewhere that I need to use the header function, but I can't figure out where to put it since the preceding portion of my code contains outputs.

I think this is the relevant code:

// Write to file if email doesn't already exist
    if ($emailexists != "yes") {

        // Write to the list and give success message
        fwrite($fh, "$_POST[email]
");
        $msg = "Your e-mail address $EmailFix was successfully added to the list!";
    }

    // Close the list
    fclose($fh);
}

Then this:

// Show success message if there was one and end script, and no errors were encountered
} elseif (isset($msg)) {
echo "<b>" . $msg . "</b>
";
echo "</body>
";
echo "</html>
";
exit;
}
  • 写回答

3条回答 默认 最新

  • dongweihuai5601 2011-06-03 20:23
    关注

    Try using

    header("Location: http://...");
    

    or

    header("Location: filename.php");
    

    Make sure there's no HTML output before calling the header function!

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号