2011-12-30 64 views
0

好吧,即時消失。我無法弄清楚如何在頭文件發送後重定向某人。這個腳本的目的是如果日期有效,他們會被重定向到編輯頁面。如果日期無效,則停止日期並告訴他們爲什麼無法編輯。標題設置後,重定向頁面使用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;} 
?> 
+3

爲什麼不把它放在沒有h讀者已經發送了嗎? – jeroen 2011-12-30 15:48:32

+0

我不明白這個問題。 PS最好使用'Location:'(注意大寫L和冒號後的空格)作爲重定向頭。 – 2011-12-30 15:48:45

回答

2

我會確保這是第一次運行的代碼,以便沒有標頭尚未發送,但如果你不能把它放在那裏,你有2種選擇:

  1. 使用JavaScript:window.location.url = ...
  2. 將元刷新標記在你的頁面的<head>部分:<meta http-equiv="refresh" content="0;url=...">

2選擇假設你不能改變之前的代碼你部分正在運行...

2

您可以使用output buffering停止渲染的任何內容。或者只要確保重定向在邏輯上完成,然後再向用戶回傳任何內容。

正確的語法是Location: http://....

注:

  • 大寫字母L
  • :和URL
  • 絕對URL之間的空隙(相對URL不符合RFC雖然可能工作在大多數瀏覽器)