繁体   English   中英

用php设置标题后重定向页面

[英]Redirecting page after headers are set with php

好的,我很茫然。 发送标头后,我不知道如何重定向某人。 该脚本的目的是在日期有效时将其重定向到编辑页面。 如果日期无效,它将停止它们并告诉他们为什么他们无法编辑。

<?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;}
?>

我将确保这是第一个运行的代码,以便尚未发送任何头,但是如果您不能将其放在此处,则有两种选择:

  1. 使用javascript: window.location.url = ...
  2. 将元刷新标签放在页面的<head>部分中: <meta http-equiv="refresh" content="0;url=...">

假设您无法在运行本节之前更改代码,则有2个选择...

您可以使用输出缓冲来停止呈现任何内容。 或者,只需确保在逻辑上完成重定向,然后再向用户回显任何内容。

正确的语法是Location: http://....

注意:

  • 大写L
  • :和URL之间的空格
  • 绝对网址(相对网址不符合RFC,尽管在大多数浏览器中可能都适用)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM