Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

How to create a config file for non programming background user

PHP

How to create a config file for non programming background user

i have a program that i need to create a config file for user.

The purpose of config file is to ease user to change setting of the program

example: user want to change the password to login to the database

This user has no knowledge in programming and the config file must be user friendly

i had created a config file using PHP code which i think is NOT GOOD ENOUGH because this config file require user to have some basic knowledge of PHP


say i have this file

***config.php****
<?php
$to = "admin@admin.com";
?>

***main.php***
function SendMailSTART()
 {
  require("config.php");
  $subject = "hi";
  $body =  "how are you";
  mail($to, $subject, $body);
 }

hence the config file above is more into coding.

How can i make a config file that is easy for non programming background user who just want to change the setting?

example
***config.txt***
#change recipient email address
email.to = admin@admin.com


0
firekiller15
Asked:
firekiller15
  • 7
  • 5
  • 4
2 Solutions
 
Hube02Commented:
My suggestion may take a different route than you're looking for.

Rather than try to come up with some kind on config file that a non programmer can understand and change, which would require me writing code to parse that config file I would do the following.

I would write a small application where the user could load a web page and enter the values that they want into a form. When they submit the form the application would check that the data entered was valid (same as any other form) and then the application would actually write the config file.
0
 
Hube02Commented:
Of course, you would need to password protect the application or keep it is a protected folder...
0
 
firekiller15Author Commented:
if i create a form to insert the value that mean everytime i want to run the program i need to first insert the value.
what i want is user change the setting only when they need to change it not everytime when they run the program they need first to set the value
how to do?

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Vel EousResearch & Development ManagerCommented:
Thought about just using DEFINE and some comments?

<?PHP

/* your email address */
define ( "EMAIL", "you@yourdomain.com" );

?>

Yes it still includes code, but with comments is very simple to understand if all the file is doing is defining constants.

Either that or do as Hube02 has suggested and produce a form with a DB back end that will allow your user to easily manipulate their data constants.
0
 
Vel EousResearch & Development ManagerCommented:
>>  if i create a form to insert the value that mean everytime i want to run the program i need to first insert the value.

That is not what Hube02 meant.  What he was meaning was create a form that initially creates the configuration file using the values collected from the form.  Thereafter, the program looks for the config file (in a similar fashion to how phpBBv3 now creates a config file).
0
 
firekiller15Author Commented:
u mean user insert the value thru form then put in to config.php. it will stay there till user reisert the value again?
0
 
Vel EousResearch & Development ManagerCommented:
>> u mean user insert the value thru form then put in to config.php. it will stay there till user reisert the value again?

Yes, just like that.
0
 
firekiller15Author Commented:
i have an idea
does it make sense if i put all the value in the text file
then i read from the file by tokenize the string in that file.
and i put those string in config.php then main call the value from config.php
0
 
Vel EousResearch & Development ManagerCommented:
You could do I suppose.  It is basically the same as Hube02's idea, just without the form.  :)
0
 
firekiller15Author Commented:
ok then how can i code this logic??
0
 
Vel EousResearch & Development ManagerCommented:
Maybe something like:
<?PHP
 
$configData = array();
 
function getInfo ()
{
	$fp = "info.txt";
	$fd = fopen ( $fp, "r" );
	$contents = fread ( $fd, filesize ( $fp ) );
 
	fclose ( $fd );
	$delimiter = "\r";
	$splitContents = explode ( $delimiter, $contents );
 
	foreach ( $splitContents as $value )
	{
		$configData[] = $value;
	}
}
 
function createConfig ()
{
	$fp = "config.php";
	$fd = fopen ( $fp, w )
 
	fwrite ( $fp, $configData );
	fclose ( $fp );
}
 
?>

Open in new window

0
 
firekiller15Author Commented:
code above doesnt seems correct to me .. too simple
0
 
Hube02Commented:
<b>"if i create a form to insert the value that mean everytime i want to run the program i need to first insert the value."</b>

No, when the user changes a setting you write a file, you don't insert it every time.

<?php
  $text = '<'.'?'.'php'.' $emailto = \'someaddress@host.com\'; ?'.'>';
  $handle = fopen('config.php, 'w');
  fwrite($handle, $text);
  fclose($handle)
?>

Then you simply need to include that file in your other app as normal

<?php
  include ('config.php');
?>

0
 
firekiller15Author Commented:
do you mind to show me some simple example of code of your logic.
example below , i still need to state the email address?
 $text = '<'.'?'.'php'.' $emailto = \'someaddress@host.com\'; ?'.'>';
0
 
Hube02Commented:
I think that I've either lost you or you lost me.

You want a config file that you include.

What my suggestion would do is set it up so that the config file is genereated once by another page.

That is what the fopen (Open the config file)
fwrite (Write what is in $text to the config file)
fclose (close the config file)

Then in you script where you need this configuration informatio you simply do

include('config.php');

with no need to parse anything because config.php will contain a line that looks like:

<?php $emailto = 'someaddress@host.com'; ?>
0
 
firekiller15Author Commented:
i think you lost me, i want to create a config file which has no php content inside.
i have found a way to do it
which is parse the line from the text file and use include function to get the lines.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now