-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodifyHosts.php
40 lines (36 loc) · 1.08 KB
/
modifyHosts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once 'getConfig.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$currentPage = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('Location: '.$currentPage);
die;
}
/**
* @param $file
* @param $data
*/
function modify_hostfile($file, $data){
$fh = fopen($file,'w+');
// using file_put_contents() instead of fwrite()
file_put_contents($file, $data);
fclose($fh);
}
/**
* @param $config_file
* @param $section
* @param $key
* @param $value
*/
function config_set($config_file, $section, $key, $value) {
$config_data = parse_ini_file($config_file, true);
$config_data[$section][$key] = $value;
$new_content = '';
foreach ($config_data as $section => $section_content) {
$section_content = array_map(function($value, $key) {
return "$key=$value";
}, array_values($section_content), array_keys($section_content));
$section_content = implode("\n", $section_content);
$new_content .= "[$section]\n$section_content\n";
}
file_put_contents($config_file, $new_content);
}