PHP Javascript maintenance page -
i used in index.php
<? include('config.php'); if($site->maintenance > 0){ echo "<script>document.location.href='maintenance'</script>"; exit; } ?> and in config.php after checked database connection
$site = mysql_fetch_object(mysql_query("select * problems")); i made table in database , called problems when put value 0, transfers me maintenance. when checked variable $site var_dump($site) outputs:
bool(false) and if checked this: var_dump($site->maintenance) outputs:
null what have manage maintenance database , when want site work change value?
why using js this? if user js off? use php instead
create table maintenance column maintenance_status, hold boolean value, 0 1... 0 => off, 1 => on, keep single record created once, , later update always...
so later create function
function check_maintenance($connection) { /* call function on every page, pass database connection var function parameter */ $query = mysqli_fetch_array(mysqli_query($connection, "select * tbl_maintenance limit 1")); /* limit 1 optional if using 1 row told you, if keeping records of previous maintenance, you've sort desc , use limit 1 */ if($query['tbl_maintenance'] == '1') { //check boolean value, if it's on redirect header('location: maintenance.php'); //redirect user maintenance page exit; } }
Comments
Post a Comment