Jump to content

Recommended Posts

Okay what im gonna do, is to make a php site that creates a .ini file..

 

Ive looked all over google trying to find this but it just can't, so if someone could help me do this it would be really nice..

 

The php form should have the following:

 

Account Name:
Password:
(and a submit button)

 

Then when you press Submit,

it should create a file called:

 

[what you entered in account name:].ini

 

and inside the file it should be like this:

 

[account]
password=[what you entered in password form]

 

here are some screens on how i want it to look like:

 

udklipbu.jpg

udklip2.jpg

 

Thanks in advance :D

Link to comment
https://forums.phpfreaks.com/topic/201479-need-help/
Share on other sites

<?php

function write_php_ini($array, $file)
{
    $res = array();
    foreach($array as $key => $val)
    {
        if(is_array($val))
        {
            $res[] = "[$key]";
            foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
        }
        else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
    }
    safefilerewrite($file, implode("\r\n", $res));
}
//////
function safefilerewrite($fileName, $dataToSave)
{    if ($fp = fopen($fileName, 'w'))
    {
        $startTime = microtime();
        do
        {            $canWrite = flock($fp, LOCK_EX);
           // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
           if(!$canWrite) usleep(round(rand(0, 100)*1000));
        } while ((!$canWrite)and((microtime()-$startTime) < 1000));

        //file was locked so now we can store information
        if ($canWrite)
        {            fwrite($fp, $dataToSave);
            flock($fp, LOCK_UN);
        }
        fclose($fp);
    }

}
?>

<form name="frm_generate_file" method="post" action="">
<input type="text" name="txt_name" value="">
<input type="password" name="pwd_password" value="">
<input type="submit" name="submit" value="submit">
</form>

<?php
if(!empty($_POST)){
$arr['Account'] = $_POST['txt_name'];
$arr['password'] = $_POST['pwd_password'];
$filename = $arr['Account'].'.ini';
write_php_ini($arr,  $filename);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/201479-need-help/#findComment-1057075
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.