0

Hello everyone I am trying to make it so I don't need to go into my php pages as much for my website, in my configuration.php page I have this.

$_CONFIG['website']['in_maint'] = false; //False if website is NOT in maintenance. True if website IS in maintenance

Which tells the site to either show a maintenance page or not, in my website administrator CP what I have been working on I have this https://i.stack.imgur.com/Yf73P.png copy image to view need more points to post a picture...

here is the code what I have put into that also,

<form action='' method='POST'>
                <div align='left'><label for='Main'><b>Turn Maintenance</b></label><input class='btn btn-primary' name='on' type='submit' value='On'></div></div>
            </form>

when I press the button it doesn't update anything is there even a way to update one php page from another? Or am I going to have to re code and make the maintenance into a database thing?

GrimmRP
  • 43
  • 8
  • You can either `fwrite` the new config file or append lines to a config file, have the code work off of a lock file, or (easiest solution) use a database. – sjagr Jan 14 '15 at 23:34
  • Editing PHP files is actually no dark magic. [PEAR::Config](http://pear.php.net/package/Config) or [libconfigedit](http://milki.include-once.org/genericplugins/genconfig.html) can do so. If it's just about a maintenance mode, then a mod_rewrite rule and state file are certainly simpler options. – mario Jan 14 '15 at 23:56

2 Answers2

1

You could do something like this

<?php 
$system = mysql_query("SELECT * FROM system");
$results = mysql_fetch_array($system);

if($results['maintenance'] == 0)
{

header('Location: /index');
exit;
}
?>

Make this as one file (.php) and add it into every page so once the database is in maintenance (which you and other admin can click if enabled or disabled) with your button you are trying to make. If you need further help, feel free to leave a comment and I can assist you further with it if you need it.

  • If you add this to every page, you will get into a never-ending loop of redirects. You probably want to check if maintenance is set and then redirect to a page where you don't include this. – jeroen Sep 28 '15 at 06:35
0

Editing a php file is never a good idea if not really necessary (so not for configuration options...), you could render your app useless and you add security problems.

A database but also a configuration file are better options, see for example http://php.net/manual/en/function.parse-ini-file.php.

A file like that is easy to write / update too and avoids any code injection problems. See also this question on SO for example.

Community
  • 1
  • 1
jeroen
  • 91,079
  • 21
  • 114
  • 132
  • Thank you Jeroen, will have to look into that hope it isn't to crazy/hard to understand. – GrimmRP Jan 14 '15 at 23:39
  • @GrimmRP It will be a lot easier than programmatically writing out correct and safe php :-) And the code is already there... – jeroen Jan 14 '15 at 23:40
  • This looks pretty advance for me but I will learn it since I really would like to be able to just click a button and put my site into maintenance without always going into my files. – GrimmRP Jan 14 '15 at 23:52
  • @GrimmRP Good luck and feel free to post new questions when you run into specific problems. – jeroen Jan 14 '15 at 23:56