Solved

How to create a config file for non programming background user

Posted on 2008-06-24
16
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 14

Expert Comment

by:Vel Eous
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:Vel Eous
Vel Eous 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:Vel Eous
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
 
LVL 14

Expert Comment

by:Vel Eous
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:Vel Eous
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

628 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