好吧,我不知所措。一旦发送标题,我无法弄清楚如何重定向某人。此脚本的目的是,如果日期有效,则会将其重定向到编辑页面。如果日期无效,则会停止它们并告诉它们无法编辑的原因。
<?php
$id = $_GET['id'];
// Define MySQL Information.
$mysqlhost="************************"; // Host name of MySQL server.
$mysqlusername="**************"; // Username of MySQL database.
$mysqlpassword="**************"; // Password of the above MySQL username.
$mysqldatabase="**************"; // Name of database where the table resides.
// Connect to MySQL.
mysql_connect("$mysqlhost", "$mysqlusername", "$mysqlpassword")or die("Could not connect to MySQL.");
mysql_select_db("$mysqldatabase")or die("Could not connect to selected MySQL database.");
$infosql = "SELECT * FROM premiersounds_users WHERE customer_id = $id";
$inforesult = mysql_query($infosql) or die(mysql_error());
$info = mysql_fetch_array($inforesult);
$l_date=$info['lockout_date'];
//Get current date from server
$format="%m/%d/%y";
$c_date=strftime($format);
//set sessions
$_SESSION['current_date'] = $c_date;
$_SESSION['lockout_date'] = $l_date;
//Check is Current date = lockout date
if ($c_date >= $l_date)
{ header("location:/planner_scripts/documnet_editors/edit_weddingplanner.php?id=$id"); } else {echo 'Whoops! Were sorry your account has been locked to edits because your event is less than 48 hours from now or your event has passed. To make changes to your event please contact your DJ.'; echo'<br/>'; echo ' Todays Date: ';echo $c_date; echo ','; echo ' Last Date for edits: '; echo $l_date;}
?>
答案 0 :(得分:2)
我会确保这是第一个运行的代码,因此尚未发送任何标题,但如果你不能将它放在那里,你有2个选择:
window.location.url = ...
<head>
部分添加元刷新标记:<meta http-equiv="refresh" content="0;url=...">
2个选项,假设您在部分运行之前无法更改代码...
答案 1 :(得分:2)
您可以使用output buffering来停止正在渲染的内容。或者,只需确保重定向在逻辑中完成,然后向用户回显任何内容。
正确的语法是Location: http://....
注意:
:
与网址