PDA

Click to See Complete Forum and Search --> : [Resolved]Editing a .ini file


Neo-dark
Jun 28th, 2007, 08:53 AM
Hey all

Im trying to edit an ini file automaticly,example:

Users fill in username($user)
Users fill in password($passwd)
Users fill in domain name($domain)

Now I want to add those values to an ini file like this

[$user]
Login=$user
Pass=$passwd
AllowChangePassword=1
Home-Ip=-= All IP Homes =-
RelativePath=1
TimeOut=600
MaxConPerIp=1
MaxUsers=0
RatioMethod=0
RatioUp=1
RatioDown=1
RatioCredit=0
MaxSpeedRcv=512
MaxSpeedSnd=512
QuotaCurrent=0
QuotaMax=0
EnableSITECHAT=1
EnableSITEWHO=1
Dir0=D:\Server\WAMP\www\Users\$domain
Attr0=RWDAMLSK


Is there an easy way to do this?
I am not an PHP expert, I barely know the syntax, But I know I would need to open the file for writing and after that for reading or something of the likes right?

Could someone give me a code snippet?

Thanks a bunch!

penagate
Jun 28th, 2007, 12:06 PM
The most straightforward way is to open the file for appending and write to it using fwrite().

$file = fopen($filename, 'a'):

fwrite($file, "[{$user}]
Login={$user}
Pass={$passwd}
AllowChangePassword=1
Home-Ip=-= All IP Homes =-
RelativePath=1
TimeOut=600
MaxConPerIp=1
MaxUsers=0
RatioMethod=0
RatioUp=1
RatioDown=1
RatioCredit=0
MaxSpeedRcv=512
MaxSpeedSnd=512
QuotaCurrent=0
QuotaMax=0
EnableSITECHAT=1
EnableSITEWHO=1
Dir0=D:\\Server\\WAMP\\www\\Users\\{$domain}
Attr0=RWDAMLSK");

fclose($file);

A more sophisticated and comprehensive approach to managing INI files would be to use the PEAR::Config (http://pear.php.net/package/Config) package.

Neo-dark
Jun 29th, 2007, 07:27 AM
Thank you ! It works great, I needed to add some extra spaces and change a few things, This is the finished code for anyone using BPFTPServer and wanting to add users by using php:


<?php
If(file_exists("D:\\Server\\WAMP\\www\\Users\\{$domain}"))
{
echo("Problem with domain name Please select an another domain name");
exit();
}
else
{
mkdir("D:\\Server\\WAMP\\www\\Users\\{$domain}", 0700);
}
$filename = "D:\\Server\\FTP Server\\users.ini";
$file = fopen($filename, 'a');

fwrite($file, "[{$user}]
Login={$user}
Pass={$passwd}
AllowChangePassword=1
Home-Ip=-= All IP Homes =-
RelativePath=1
TimeOut=600
MaxConPerIp=1
MaxUsers=0
RatioMethod=0
RatioUp=1
RatioDown=1
RatioCredit=0
MaxSpeedRcv=512
MaxSpeedSnd=512
QuotaCurrent=0
QuotaMax=0
EnableSITECHAT=1
EnableSITEWHO=1
Dir0=D:\\Server\\WAMP\\www\\Users\\{$domain}
Attr0=RWDAMLSK
");

fclose($file);
?>

Thank you for registering at cyberdrain networks!
Your account will be activated within 30 minutes.
If you would like a database/Cyberdrain.com Email adress please mail info@cyberdrain.com
If you have any problems at all feel free to contact us!


The place its used is http://www.cyberdrain.com/account.php .

Thank you again!