Vicious88 Posted February 4, 2011 Share Posted February 4, 2011 I'm new to PHP (I've done some of the basic stuff, but I'm far from anything too advanced). I'm looking to make a site with some Universal (not user specific) variables which can be configured in a control panel, but I just don't know where to begin. To give an example of what I'm looking to do: In the header.php, for instance, I'd like to allow the admin an option to display either the company logo (png) or the company name in text format. They would chose which of the two options they want (and fill out what the "company name" should be) in a separate config.php page. So, in essence, I suppose what I'm asking is "1) How do I make a configuration form store data indefinitely? 2) How do I make other pages reference that data?" Quote Link to comment https://forums.phpfreaks.com/topic/226635-universal-variables/ Share on other sites More sharing options...
.josh Posted February 4, 2011 Share Posted February 4, 2011 1) Store the data in a flatfile or database 2) retrieve the data from a flatfile or database Whether you choose database or flatfile, you can make a "config" type script that will load up variables and you can include that script in other scripts with include or require Quote Link to comment https://forums.phpfreaks.com/topic/226635-universal-variables/#findComment-1169689 Share on other sites More sharing options...
jcbones Posted February 4, 2011 Share Posted February 4, 2011 An example of doing this with a flatfile: <?php $header = NULL; $body = NULL; $footer = NULL; if(isset($_POST)) { foreach($_POST as $k => $v) { $$k = $v; } } $write = "<?php \$header = '$header'; \$body = '$body'; \$footer = '$footer'; ?>"; file_put_contents('variables.php',$write); echo <<<EOF <form action="" method="post"> <label for="header">Header</label><br /> <input type="text" name="header" value="" /><br /> <br /> <label for="body">Body</label><br /> <textarea cols="40" rows="10" name="body"></textarea><br /><br /> <label for="footer">Footer</label><br /> <input type="text" name="footer" value="" /><br /><br /> <input type="submit" name="submit" value="SUBMIT" /> </form> EOF; if(file_exists('variables.php')) { include('variables.php'); echo '<div>' . $header . '</div><div>' . $body . '</div><div>' . $footer . '</div>'; } ?> Rather crude, but hey it was 2 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/226635-universal-variables/#findComment-1169700 Share on other sites More sharing options...
Vicious88 Posted February 5, 2011 Author Share Posted February 5, 2011 I certainly appreciate the feedback, and will attempt the flatfile method, as it seems the most straight forward. Quote Link to comment https://forums.phpfreaks.com/topic/226635-universal-variables/#findComment-1170123 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.