firekiller15
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Of course, you would need to password protect the application or keep it is a protected folder...
ASKER
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?
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?
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.
<?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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
u mean user insert the value thru form then put in to config.php. it will stay there till user reisert the value again?
>> 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.
Yes, just like that.
ASKER
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
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
You could do I suppose. It is basically the same as Hube02's idea, just without the form. :)
ASKER
ok then how can i code this logic??
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 );
}
?>
ASKER
code above doesnt seems correct to me .. too simple
<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');
?>
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');
?>
ASKER
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\'; ?'.'>';
example below , i still need to state the email address?
$text = '<'.'?'.'php'.' $emailto = \'someaddress@host.com\'; ?'.'>';
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'; ?>
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'; ?>
ASKER
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.
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.