Lamez Posted August 25, 2007 Share Posted August 25, 2007 I have seen this in forums and such, how can I change the index file saying "Under Construction" or what ever by using php. then I can login to the admin pane and change it back. Any ideas? -Thanks, Once Again! Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2007 Share Posted August 25, 2007 It can be done in many different ways, probably the easiest though is to set a constant within some sort of configuration file (this file could be editable vai your control panel), then simply check what is is set to within your index page. eg; config.php <?php define("SITE_IS_LIVE",FALSE) ; // set to TRUE to make site active. ?> index.php <?php if (!SITE_IS_LIVE) { die("Under Construction"); } // rest of site. ?> Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 I know its not my topic but i have a question here. How will one be able to modify the constant from ex. the admin panel. In your case make "SITE_IS_LIVE" true. It may be dumb but i dont know Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2007 Share Posted August 25, 2007 One easy way would be to load a page with a form in it. This form would display the config.php for editing. Once you submit the form, the changes are saved. Something like.... editconfig.php <?php if (isset($_POST['submit'])) { $f = fopen("config.php","w"); fwrite($f,$_POST['config']); fclose($f); } else { $f = fopen("config.php","r"); $config = fread($f, filesize("config.php")); fclose($handle); echo "<form method='post'>"; echo " <textarea name='config'>$config</textarea>"; echo " <input type='submit' name='submit' value='save'>"; echo "</form>"; } ?> Quote Link to comment Share on other sites More sharing options...
rofl90 Posted August 25, 2007 Share Posted August 25, 2007 Easier ways in config.php make a variable $sitestatus then in your head.php file check if the variable = 1 or 0 and if one kill the script and replace with Site under construction, thats the most used way anyway Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2007 Share Posted August 25, 2007 That is no different to the logic of the method Ive just described. Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 Thnx thorpe, it makes sense now. @rofl90 the same exact thing, except the use of the constant vs variable. Id go rather for a constant, which im sure will not change value accidentally Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 25, 2007 Share Posted August 25, 2007 Wow, you guys are making wayyyyyyyyy to complicated.. just make a database table called WEBSITE_STATS, and have a coloumn called online... Just update the coloumn online to false or true from the admin panel... <?php ///Top Of the Page $query=mysql_fetch_assoc(mysql_query("SELECT * FROM WEBSITE_STATS")); if($query['online']=="false"){ die("Sorry, Website Has Been Disabled by the admin..."); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2007 Share Posted August 25, 2007 The problem with using a database for such tasks is sometimes you want to close the site so you can actually do some database maintanence, and sometimes this will involve taking the db offline. I allways use simple files for configurations. Much easier to handle, and more reliable. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 25, 2007 Share Posted August 25, 2007 then I guess you can just use fopen, and fwrite tools... file based is most reliable. Quote Link to comment Share on other sites More sharing options...
Lamez Posted August 25, 2007 Author Share Posted August 25, 2007 alright, but how can I do this by a submit button? Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2007 Share Posted August 25, 2007 Its all there, read the posts above. Quote Link to comment Share on other sites More sharing options...
Lamez Posted August 25, 2007 Author Share Posted August 25, 2007 omg I am so sorry I over read, thank you guys so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.