Skip to content

Instantly share code, notes, and snippets.

@khaeransori
Created December 13, 2016 16:02
Show Gist options
  • Save khaeransori/429519fb4a0a3b024299c2cf8744fafd to your computer and use it in GitHub Desktop.
Save khaeransori/429519fb4a0a3b024299c2cf8744fafd to your computer and use it in GitHub Desktop.
<?php
const FILENAME = 'loadlog.ini';
const FILEPATH = './' . FILENAME;
$foo = $_POST['foo'];
$bar = $_POST['bar'];
$content = 'foo=' . $foo;
$content .= '\n'; // \n are ascii code for breakline a.k.a enter
$content .= 'bar=' . $bar;
// write to file first if there's payload
if ($foo || $bar) {
file_put_contents(FILEPATH, $content);
}
// read file and parse it
$parsed_file = parse_ini_file(FILEPATH);
/**
* it should be parsed to array
* so you can access it like $parsed_file['foo']
*/
print_r($parsed_file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment