Jump to content

Universal Variables?


Vicious88

Recommended Posts

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?"

Link to comment
https://forums.phpfreaks.com/topic/226635-universal-variables/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/226635-universal-variables/#findComment-1169689
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/226635-universal-variables/#findComment-1169700
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.