Solved

How to create a config file for non programming background user

Posted on 2008-06-24
16
206 Views
Last Modified: 2008-07-21
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
Comment
Question by:firekiller15
  • 7
  • 5
  • 4
16 Comments
 
LVL 18

Accepted Solution

by:
Hube02 earned 125 total points
ID: 21862305
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
 
LVL 18

Expert Comment

by:Hube02
ID: 21862317
Of course, you would need to password protect the application or keep it is a protected folder...
0
 

Author Comment

by:firekiller15
ID: 21862363
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
 
LVL 14

Expert Comment

by:Tchuki
ID: 21862372
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
 
LVL 14

Assisted Solution

by:Tchuki
Tchuki earned 125 total points
ID: 21862381
>>  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
 

Author Comment

by:firekiller15
ID: 21862524
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
 
LVL 14

Expert Comment

by:Tchuki
ID: 21862530
>> 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
 

Author Comment

by:firekiller15
ID: 21862634
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Expert Comment

by:Tchuki
ID: 21862644
You could do I suppose.  It is basically the same as Hube02's idea, just without the form.  :)
0
 

Author Comment

by:firekiller15
ID: 21862663
ok then how can i code this logic??
0
 
LVL 14

Expert Comment

by:Tchuki
ID: 21862739
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
 

Author Comment

by:firekiller15
ID: 21862991
code above doesnt seems correct to me .. too simple
0
 
LVL 18

Expert Comment

by:Hube02
ID: 21864425
<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
 

Author Comment

by:firekiller15
ID: 21871340
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
 
LVL 18

Expert Comment

by:Hube02
ID: 21884817
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
 

Author Comment

by:firekiller15
ID: 21937253
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now