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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.