我寫一個PHP代碼由管理員設定一個截止日期,讓管理員通過輸入形式daedline日期,它會存儲在數據庫中,現在我想用這個最後期限,只要檢查用戶要訪問的網頁,如果截止日期過期的用戶無法訪問該網頁時,他會自動轉移到所謂的「closed.html」頁面上,如果沒有用戶可以訪問它..我已經試過這個代碼但它保持移動到closed.html頁面,即使日期尚未過期!想法請嗎?PHP - 截止日期查詢
<?php
session_start();
$Load=$_SESSION['login_user'];
$sql= "Select deadline from schedule_deliverables";
$deadline = mysql_query($sql);
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($deadline);
if ($expiration_date > $today) {
echo "<meta http-equiv='refresh' content='1;URL=Check_file.php'>"; //user can access the page
} else {
echo "<meta http-equiv='refresh' content='1;URL=closed.html'>"; //deadline is past user can't access
}
?>
而正是你建立你的數據庫連接?只是'mysql_query'不會削減它(也被棄用的方式,使用庫MySQLi或PDO來代替,看到的mysql_query [手動](http://php.net/mysql_query))。這是完整的代碼還是你遺漏了某些部分? – Oldskool
請不要使用'mysql_ *'功能更多http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/12860140#12860140 –