我在我的index.php中使用了这个
<?
include('config.php');
if($site->maintenance > 0){
echo "<script>document.location.href='maintenance'</script>";
exit;
}
?>
在检查数据库连接后在我的 config.php 中
$site = mysql_fetch_object(mysql_query("SELECT * FROM problems"));
我在数据库中创建了一个表并将其命名为 problems
但即使我将值设置为 0,它也会将我转移到维护状态。当我检查变量$site
时通过var_dump($site)
它输出:
bool(false)
如果我像这样检查它:var_dump($site->maintenance)
它输出:
NULL
我需要做什么来管理数据库的维护,当我希望我的网站正常工作时,我需要更改值?
最佳答案
为什么要使用 JS 来实现这个目的?如果用户JS关闭了怎么办?我会使用 PHP 来代替
创建一个维护表,其中有一列maintenance_status
,现在它将保存一个 bool 值,0 1... 0 => 关闭,1 => 开启,将仅保留一条记录它将被创建一次,稍后将始终更新......
所以现在你创建这个函数
function check_maintenance($connection) { /* Call this function on every page,
pass your database connection var
as a function parameter */
$query = mysqli_fetch_array(mysqli_query($connection, "SELECT * FROM tbl_maintenance LIMIT 1"));
/* Limit 1 is optional if you are using only 1 row as I told you,
if you are keeping records of the previous maintenance, probably
you've to sort desc and use limit 1 */
if($query['tbl_maintenance'] == '1') { //Check boolean value, if it's on than redirect
header('Location: maintenance.php'); //Redirect the user to maintenance page
exit;
}
}
关于javascript - PHP Javascript 维护页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16373810/