Website Status


First off open phpMyAdmin and run the following:
PHP Code
  1. CREATE TABLE `site_stats` (
  2. `sid` INT( 11 ) NOT NULL auto_increment,
  3. `stats` CHAR( 7 ) NOT NULL default 'Online',
  4. `immunity` CHAR( 3 ) NOT NULL default 'Yes',
  5. `immunelvl` INT( 2 ) NOT NULL default '6',
  6. `forums` INT( 1 ) NOT NULL default '1',
  7. `signups` INT( 1 ) NOT NULL default '1',
  8. PRIMAY KEY(`sid`)
  9. );
  10. INSERT INTO `site_stats` (`sid`,`stats`,`immunity`,`immunelvl`,`forums`,`signups`) VALUES ('1','Online','Yes','6','1','1');


I suggest doing them separate though :S

Next make a new file name it: stats.php

In that file place the following code Be Sure To Read it::
PHP Code
  1. <?php
  2. if(!$logged[username] && !$logged[userlevel]){ //check if user is logged in
  3. echo "You Are Not Logged In!"; //echo this if they are not
  4. }elseif($logged[username] && $logged[userlevel] != "6"){ //check if user is an admin
  5. echo "You Are Not An Admin!"; //echo this if they aren't
  6. }else{ //or if everything is ok..
  7. if(!isset($_GET[edit])){ //check if ?edit is in the address bar
  8. $get = mysql_query("SELECT * FROM `site_stats` WHERE sid = '1';"); //select data from the table
  9. if(mysql_error()){ //if there is an error
  10. echo "You have an error in the SQL Query on line: 18"; //echo this
  11. }else{ //or not
  12. $r = mysql_fetch_array($get); //array the info to be echoed.
  13. echo "<p align=\"center\"><a href=\"stats.php?edit\">Edit Site Status</a>
  14. <b>Website Status</b>: $r[stats]<Br />
  15. <b>Admin Immunity</b>: $r[immunity]
  16. <b>Immunity Level</b>: $r[immunelvl]
  17. <b>Forum Status</b>:"; //echo part of the information
  18. if($r[forums] == "1"){ //check if the forums are online
  19. echo "&nbsp;Online"; //if they are
  20. }else{ //if they are something else..
  21. echo "&nbsp;Offline"; //if they are of
  22. } //end forums check
  23. echo "<b>Sign-up Status</b>:"; //signup status
  24. if($r[signups] == "1"){ //if its online
  25. echo "&nbsp;Online"; //say thing
  26. }else{ //or if it is something else
  27. echo "&nbsp;Offline"; //echo this
  28. } //end check
  29. echo "</p>"; //end paragraph
  30. } //end error check
  31. }else{ //or if it is in the address bar
  32. $get = mysql_query("SELECT * FROM `site_stats` WHERE sid = '1';"); //get info
  33. if(mysql_error()){ //check if thers an error
  34. echo "You have an error in the SQL Query on line: 18"; //if there is echo that
  35. }else{ //or not...
  36. $r = mysql_fetch_array($get);
  37. if(!$_POST[edit]){ //check if the form was submitted
  38. echo "<form method=\"post\" action=\"\">
  39. <table width=\"150\" cellpadding=\"0\" cellspacing=\"2\">
  40. <tr>
  41. <td width=\"150\" align=\"center\" valign=\"middle\">
  42. <b>Site Status</b>:
  43. </td>
  44. <td width=\"150\" align=\"center\" valign=\"middle\">
  45. <select name=\"stats\">"; //Yay tables forms and data inputs =O!!!
  46. if($r[stats] == "Online"){ //if status is online
  47. echo "<option value=\"Online\" selected=\"selected\">Online</option"; //online is selected
  48. }else{ //but if it isn't
  49. echo "<option value=\"Online\">Online</option>"; //its not
  50. } //end online field
  51. if($r[stats] == "Offline"){ //or if its offline
  52. echo "<option value=\"Offline\" selected=\"selected\">Offline</option>"; //offline is selected
  53. }else{ //maybe its not....
  54. echo "<option value=\"Offline\">Offline</option>"; //its not selected
  55. } //end offline check
  56. echo "</select>
  57. </td>
  58. </tr>
  59. <tr>
  60. <td width=\"150\" align=\"center\" valign=\"middle\">
  61. <b>Admin Immunity</b>:
  62. </td>
  63. <td width=\"150\" align=\"center\" valign=\"middle\">
  64. <select name=\"immunity\">"; //continue data
  65. if($r[immunity] == "Yes"){ //check if admin immunty is on
  66. echo "<option value=\"Yes\" selected=\"selected\">Yes</option>"; //if it is...yes is selected
  67. }else{ //or if its no
  68. echo "<optiong value=\"Yes\">Yes</option>"; //its not selected
  69. } //end yes check
  70. if($r[immunity] == "No"){ //immunity check :P
  71. echo "<option value=\"No\" selected=\"selected\">No</option>"; //it is YAY
  72. }else{ //or if it isint No
  73. echo "<option value=\"No\">No</option>"; //if not
  74. } //end no check
  75. echo "</select>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td width=\"150\" align=\"center\" valign=\"middle\">
  80. <b>Immune Level</b>:
  81. </td>
  82. <td width=\"150\" align=\"center\" valign=\"middle\">
  83. <input type=\"text\" name=\"level\" value=\"$r[immunelvl]\" size=\"15\" maxlength=\"2\">
  84. </td>
  85. </tr>
  86. <tr>
  87. <td width=\"150\" align=\"center\" valign=\"middle\">
  88. <b>Forums Status</b>:
  89. </td>
  90. <td width=\"150\" align=\"center\" valign=\"middle\">
  91. <select name=\"forums\">"; //continue with some more information...
  92. if($r[forums] == "1"){ //check if forums are online
  93. echo "<option value=\"1\" selected=\"selected\">Online</option>"; //if they are
  94. }else{ //or if they aren't
  95. echo "option value=\"1\">Online</option>"; //echo online field not selcted
  96. } //end check
  97. if($r[forums] == "0"){ //check if forums are offline
  98. echo "<option value=\"0\" selected=\"selected\">Offline</option>"; //if they are
  99. }else{ //or if they aren't
  100. echo "option value=\"0\">Offline</option>"; //echo offline field not selcted
  101. } //end check
  102. echo "</select>
  103. </td>
  104. </tr>
  105. </tr>
  106. <td width=\"150\" align=\"center\" valign=\"middle\">
  107. <b>Sign-up Status</b>:
  108. </td>
  109. <td width=\"150\" align=\"center\" valign=\"middle\">
  110. <select name=\"signups\">"; //more information and some moer table :)
  111. if($r[signups] == "1"){ //if signups is online
  112. echo "<option value=\"1\" selected=\"selected\">Online</option>"; //if it is
  113. }else{ //or not
  114. echo "<option value=\"1\">Online</option>"; //its not checked
  115. } //end check
  116. if($r[signups] == "0"){ //or maybe offine?
  117. echo "<option value=\"0\" selected=\"selected\">Offline</option>"; //checked
  118. }else{ //if it isint 0
  119. echo "<option value=\"0\">Offline</option>"; //its not checked :O
  120. } //end check
  121. echo "</select>
  122. </td>
  123. </tr>
  124. <td>
  125. <td width=\"300\" colspan=\"3\" align=\"center\" valign=\"middle\">
  126. <input type=\"submit\" name=\"edit\" value=\"Update Stats\">
  127. </td>
  128. </tr>
  129. </table>
  130. </form>"; //finish up the form and information
  131. }else{ //or if the form was submitted
  132. $stats = strip_tags(htmlspecialchars($_POST[stats])); //clean stats
  133. $immunity = strip_tags(htmlspecialchars($_POST[immunity])); //clean immunity
  134. $imunelvl = (int) strip_tags(htmlspecialchars($_POST[level])); //clean immune level
  135. $forums = strip_tags(htmlspecialchars($_POST[forums])); //clean forums
  136. $signups = strip_tags(htmlspecialchars($_POST[signups])); //cheak signups
  137. $mysql = mysql_query("UPDATE `site_stats` SET `stats` = '$stats', immunity = '$immunity', `immunelvl` = '$immunelvl', `forums` = '$forums', `signups` = '$signups' WHERE sid = '1';");
  138. if(!mysql_error()){ //if no error encountered
  139. echo "Site Status Updated!"; //success
  140. }else{ //or not?
  141. echo "There is an error in the syntax of line 137! please check it out!"; //error
  142. } //end error
  143. } //end form check
  144. } //end error check
  145. } //end edit check
  146. } //end login check
  147. ?>


Next open your config.php and add:
PHP Code
  1. $sets = mysql_query("SELECT * FROM site_stats WHERE `sid` = '1';");
  2. $setting = mysql_fetch_array($sets);
  3. //get the info and let it be used all over the site :)


Thats done, it can be called out in basically all files upon your website :)

Now open up forum.php if you have it from this site and do the follow modifications:

FIND:
PHP Code
  1. if($logged[username])
  2. {


Add After:
PHP Code
  1. if($setting[forums] == "0"){ //check if forums are offline
  2. echo "Forums Offline, please check back later"; //say they are offline
  3. }else{


Next, these lines can be found near the end but
Find:
PHP Code
  1. break;
  2. }
  3. }


Add After:
PHP Code
  1. }


Thats that file!

Now you will want to open up your register.php and do the following modifications:

FIND
PHP Code
  1. echo "<center>";
  2. //checks if there trying to veriy there account


Add After:
PHP Code
  1. if($setting[signups] == "0"){
  2. echo "Signups Are Disabled, Please Check Back Later!";
  3. }else{


FIND:
PHP Code
  1. </form>";
  2. }
  3. echo "<center>";


Replace with:
PHP Code
  1. </form>";
  2. }
  3. echo "</center>";


Then add after:
PHP Code
  1. }


Now, if you have your template split into 2 files add this to the top of the header file or index.php
PHP Code
  1. <?php
  2. session_start(); //allow sessions
  3. include("config.php"); //get config
  4. if(!$logged[username] && $setting[stats] == "Offline"){ //check if not logged in and site stats is offline
  5. exit("$setting[reason]"); //uh ohs it is!
  6. }elseif($logged[username] && $setting[stats] == "Offline" && $setting[immunity] == "Yes"){ //check if logged in and stats is offline but immunity is on
  7. if($logged[userlevel] != $setting[immunelvl]){ //see if levels are same
  8. exit("$setting[reason]"); //die reaosn for offline :S if not
  9. }else{ //or if they are
  10. } //show the site, this is ending the level check :)
  11. }elseif($logged[username] && $setting[stats] == "Offline" && $setting[immunity] == "No"){ //or if they are logged in, stats is offline, and immunity is off
  12. exit("$setting[reason]"); //die with the reason
  13. }elseif($setting[stats] == "Online"){ //or if the site is online
  14. } //show site and finish the script :)
  15. ?>


That is all! if you encounter any errors post them here and i'll respond ASAP. i have tested this and it came up clean.

PHP Code
  1. <b>Updated by Daniel error fix, (index.php)</b>
  2. Parse error: syntax error, unexpected ';' in /index.php on line 12
  3.  
  4. Missing ']' after $setting[immunity
ShadowMage's Avatar
Author:
Views:
3,068
Rating:
Posted on Thursday 31st July 2008 at 09:01 AM
Dalez
Dalez's Avatar
When i change "stats" to "Online" and then go to edit it again, it goes "OnlineOffline", without any drop down bit. Anyone know how to fix this?
Posted on Monday 9th June 2008 at 05:11 AM
Adam981
Adam981's Avatar
alright well i got everything to work except that when u go to change the "forum" stats to online or offline it only displays the online part.
Posted on Thursday 5th June 2008 at 05:03 PM
Adam981
Adam981's Avatar
Parse error: syntax error, unexpected ';' in /home/crystal/public_html/index.php on line 12

i cant fix this.. can anyone help?
Posted on Thursday 5th June 2008 at 04:50 PM
Adam981
Adam981's Avatar
haha nevermind i got it, for anyone else that can't get mysql to work, "PRIMAY KEY(`sid`)" The error is that "PRIMARY" is missing the "R" :) also not sure but u might need to add )ENGINE=MyISAM; at the end :)
Posted on Thursday 5th June 2008 at 05:30 AM
Adam981
Adam981's Avatar
I cant get the mysql to work :(
Posted on Wednesday 9th April 2008 at 05:49 PM
Dalez
Dalez's Avatar
Oh nvm, done it! Thanks.
Posted on Sunday 23rd March 2008 at 06:18 PM
Dalez
Dalez's Avatar
The mysql doesn't work, and i have done them seperate.
Posted on Thursday 28th June 2007 at 06:32 AM
MOD-Dan
MOD-Dan's Avatar
And it stops you signing up and you need to be admin to get onto the site whilst its offline
Posted on Thursday 14th June 2007 at 04:24 PM
ShadowMage
ShadowMage's Avatar
This is indeed for the user system for it has the admin panel to edit site status, forum status, and sign-up status.
Posted on Wednesday 13th June 2007 at 02:54 PM
Dean
Dean's Avatar
because hes using the members system for admins allowing them to turn it off and online.