write_php_ini
Ik ben bezig geweest met data naar een ini file te zetten. Maar ik kom er niet achter hoe ik iets update.
Code (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
41
42
43
44
45
46
47
48
49
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
41
42
43
44
45
46
47
48
49
$hostname = $_POST['hostname'];
$username = $_POST['username'];
$password = $_POST['password'];
$database = $_POST['database'];
$prefix = $_POST['prefix'];
$dbData = array(
'dbData' => array(
'hostname' => $hostname,
'username' => $username,
'password' => $password,
'database' => $database,
'prefix' => $prefix,
));
write_php_ini('config.ini', true);
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, 'config.ini'))
{
$startTime = microtime(TRUE);
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(TRUE)-$startTime) < 5));
//file was locked so now we can store information
if ($canWrite)
{ fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
}
}
$username = $_POST['username'];
$password = $_POST['password'];
$database = $_POST['database'];
$prefix = $_POST['prefix'];
$dbData = array(
'dbData' => array(
'hostname' => $hostname,
'username' => $username,
'password' => $password,
'database' => $database,
'prefix' => $prefix,
));
write_php_ini('config.ini', true);
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, 'config.ini'))
{
$startTime = microtime(TRUE);
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(TRUE)-$startTime) < 5));
//file was locked so now we can store information
if ($canWrite)
{ fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
}
}
maar als ik dan bijvoorbeeld iets erbij wilt zoals maar zonder dat je die andere velden hoeft in te vullen, hoe doe ik dat dan? Met een hidden form? Of...
Ja, die kan je dan in een hidden form zetten of met parse_ini_file() uit je databestand halen.
Dit lijkt mij niet kloppen. Het gebruik van parameters in de declaratie en de aanroep stemt niet overeen.
Inderdaad, hij verwacht eerst je array met ALLE gegevens die je wilt opslaan, en daarna de bestandsnaam van je .ini-file die hij moet beschrijven.
Dit script is van - Ariën - :P
Maar mijn voorbeeld die ik eerder gaf werkte prima.
Code (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
error_reporting(0);
if ($_GET['stap'] == 1) {
$headertitle = "Stap 1";
$subtitle = "Hieronder kunt u uw database gegevens invullen. Als je hier niet zeker van bent, neem dan contact op met je webhost.";
$content = '<form method="POST" action="/installeren?stap=1">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="dbname">Database naam</label></th>
<td><input name="database" id="dbname" type="text" size="25" value="paneel"></td>
<td>De naam van de database die je wilt gebruiken voor het paneel.</td>
</tr>
<tr>
<th scope="row"><label for="uname">Gebruikersnaam</label></th>
<td><input name="username" id="uname" type="text" size="25" value="gebruikersnaam"></td>
<td>Uw database gebruikersnaam.</td>
</tr>
<tr>
<th scope="row"><label for="pwd">Wachtwoord</label></th>
<td><input name="password" id="pwd" type="text" size="25" value="wachtwoord" autocomplete="off"></td>
<td>Uw database wachtwoord.</td>
</tr>
<tr>
<th scope="row"><label for="dbhost">Database Host</label></th>
<td><input name="hostname" id="dbhost" type="text" size="25" value="localhost"></td>
<td>Je zou deze informatie kunen krijgen door je webhost, als <code>localhost</code> niet werkt.</td>
</tr>
<tr>
<th scope="row"><label for="prefix">Tabel Prefix</label></th>
<td><input name="prefix" id="prefix" type="text" value="panel_" size="25"></td>
<td>Als je meerdere panelen in 1 database wilt, verander dan dit.</td>
</tr>
</tbody></table>
<p class="step"><input name="datadb" type="submit" value="Verzenden" class="button button-large"></p>
</form>';
} elseif ($_GET['stap'] == 2) {
$headertitle = "Stap 2";
$subtitle = "Hieronder kunt u uw bedrijf gegevens invullen. Deze gegevens kan je later nog veranderen.";
$content = '<form method="POST" action="/installeren?stap=1">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="company">Bedrijfsnaam</label></th>
<td><input name="company" id="company" type="text" size="25" value="paneel"></td>
<td>De naam van het bedrijf.</td>
</tr>
<tr>
<th scope="row"><label for="logo1">Logo</label></th>
<td><input name="logo" id="logo1" type="text" size="25" value=""></td>
<td>Het logo van het bedrijf.</td>
</tr>
<tr>
<th scope="row"><label for="ss">Site status</label></th>
<td><input name="sitestatus" id="ss" type="text" size="25" value="Online" autocomplete="off"></td>
<td>De status van het paneel, standaard is online.</td>
</tr>
</tbody></table>
<p class="step"><input name="datadb" type="submit" value="Verzenden" class="button button-large"></p>
</form>';
} elseif ($_GET['stap'] == 3) {
$headertitle = "Stap 3";
$title = "";
} elseif (empty($_GET['stap'])) {
$headertitle = "Start";
$title = "<h1>Voor we gaan starten</h1>";
$subtitle = "Welkom op de configuratie voor het nieuwste community paneel. Voor we gaan starten, hebben we wat informatie nodig voor de website optezetten. Je moet de volgende dingen weten voor je verder gaat.";
$content = "<ol>
<li>Database gegevens</li>
<li>Bedrijf gegeven/details</li>
</ol>";
$subcontent = "We gaan deze informatie gebruiken voor de configuratie het paneel en het instellen van de database, mocht het niet werken kun je het op een later tijdstip opnieuw proberen.";
$extra = "Als het goed is, werden de database gegevens aan u geleverd door uw webhost. Als u deze informatie niet hebt, dan moet u uw webhost contacteren. Als je al klaar bent...";
$button = '<a href="?stap=1" class="button button-large">Beginnen!</a>';
} else {
$headertitle = "...";
$title = "Deze stap kan niet worden gevonden.";
}
$hostname = $_POST['hostname'];
$username = $_POST['username'];
$password = $_POST['password'];
$database = $_POST['database'];
$prefix = $_POST['prefix'];
$company = $_POST['company'];
$logo = $_POST['logo'];
$sitestatus = $_POST['sitestatus'];
if (empty($hostname)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$hostname = $_CONFIG['hostname'];
}
if (empty($username)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$username = $_CONFIG['username'];
}
if (empty($password)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$password = $_CONFIG['password'];
}
if (empty($database)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$database = $_CONFIG['database'];
}
if (empty($prefix)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$prefix = $_CONFIG['prefix'];
}
if (empty($company)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$company = $_CONFIG['company'];
}
if (empty($logo)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$logo = "https://upload.wikimedia.org/wikipedia/commons/3/33/Vanamo_Logo.png";
}
if (empty($sitestatus)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$sitestatus = "Online";
}
$array = array(
'hostname' => $hostname,
'username' => $username,
'password' => $password,
'database' => $database,
'prefix' => $prefix,
'company' => $company,
'logo' => $logo,
'site_status' => $sitestatus,
'encoding' => 'ANSI'
);
write_php_ini($array, "../datafile.ini");
/*DO NOT EDIT UNDER THIS LINE! */
/* ==============================================================*/
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(TRUE);
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(TRUE)-$startTime) < 5));
//file was locked so now we can store information
if ($canWrite)
{ fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
header('?stap=2');
}
}
if (isset($_POST['datadb'])) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$mysqli = @new mysqli ($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database']);
if (mysqli_connect_error()) {
echo '<p style="color: red;">Niet alle gegevens zijn goed ingevoerd. Probeer het opnieuw.</p>';
} else {
header('Location: ?stap=2');
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?=$headertitle?> - Configuratie</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel='stylesheet' id='buttons-css' href='paneel/assets/css/installation.button.css' type='text/css' media='all'>
<link rel='stylesheet' id='install-css' href='paneel/assets/css/installation.css' type='text/css' media='all'>
</head>
<body class="wp-core-ui">
<?=$title?>
<p><?=$subtitle?></p>
<?=$content?>
<p><?=$subcontent?>
<p><?=$extra?></p>
<p class="step"><?=$button?></p>
</body>
</html>
error_reporting(0);
if ($_GET['stap'] == 1) {
$headertitle = "Stap 1";
$subtitle = "Hieronder kunt u uw database gegevens invullen. Als je hier niet zeker van bent, neem dan contact op met je webhost.";
$content = '<form method="POST" action="/installeren?stap=1">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="dbname">Database naam</label></th>
<td><input name="database" id="dbname" type="text" size="25" value="paneel"></td>
<td>De naam van de database die je wilt gebruiken voor het paneel.</td>
</tr>
<tr>
<th scope="row"><label for="uname">Gebruikersnaam</label></th>
<td><input name="username" id="uname" type="text" size="25" value="gebruikersnaam"></td>
<td>Uw database gebruikersnaam.</td>
</tr>
<tr>
<th scope="row"><label for="pwd">Wachtwoord</label></th>
<td><input name="password" id="pwd" type="text" size="25" value="wachtwoord" autocomplete="off"></td>
<td>Uw database wachtwoord.</td>
</tr>
<tr>
<th scope="row"><label for="dbhost">Database Host</label></th>
<td><input name="hostname" id="dbhost" type="text" size="25" value="localhost"></td>
<td>Je zou deze informatie kunen krijgen door je webhost, als <code>localhost</code> niet werkt.</td>
</tr>
<tr>
<th scope="row"><label for="prefix">Tabel Prefix</label></th>
<td><input name="prefix" id="prefix" type="text" value="panel_" size="25"></td>
<td>Als je meerdere panelen in 1 database wilt, verander dan dit.</td>
</tr>
</tbody></table>
<p class="step"><input name="datadb" type="submit" value="Verzenden" class="button button-large"></p>
</form>';
} elseif ($_GET['stap'] == 2) {
$headertitle = "Stap 2";
$subtitle = "Hieronder kunt u uw bedrijf gegevens invullen. Deze gegevens kan je later nog veranderen.";
$content = '<form method="POST" action="/installeren?stap=1">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="company">Bedrijfsnaam</label></th>
<td><input name="company" id="company" type="text" size="25" value="paneel"></td>
<td>De naam van het bedrijf.</td>
</tr>
<tr>
<th scope="row"><label for="logo1">Logo</label></th>
<td><input name="logo" id="logo1" type="text" size="25" value=""></td>
<td>Het logo van het bedrijf.</td>
</tr>
<tr>
<th scope="row"><label for="ss">Site status</label></th>
<td><input name="sitestatus" id="ss" type="text" size="25" value="Online" autocomplete="off"></td>
<td>De status van het paneel, standaard is online.</td>
</tr>
</tbody></table>
<p class="step"><input name="datadb" type="submit" value="Verzenden" class="button button-large"></p>
</form>';
} elseif ($_GET['stap'] == 3) {
$headertitle = "Stap 3";
$title = "";
} elseif (empty($_GET['stap'])) {
$headertitle = "Start";
$title = "<h1>Voor we gaan starten</h1>";
$subtitle = "Welkom op de configuratie voor het nieuwste community paneel. Voor we gaan starten, hebben we wat informatie nodig voor de website optezetten. Je moet de volgende dingen weten voor je verder gaat.";
$content = "<ol>
<li>Database gegevens</li>
<li>Bedrijf gegeven/details</li>
</ol>";
$subcontent = "We gaan deze informatie gebruiken voor de configuratie het paneel en het instellen van de database, mocht het niet werken kun je het op een later tijdstip opnieuw proberen.";
$extra = "Als het goed is, werden de database gegevens aan u geleverd door uw webhost. Als u deze informatie niet hebt, dan moet u uw webhost contacteren. Als je al klaar bent...";
$button = '<a href="?stap=1" class="button button-large">Beginnen!</a>';
} else {
$headertitle = "...";
$title = "Deze stap kan niet worden gevonden.";
}
$hostname = $_POST['hostname'];
$username = $_POST['username'];
$password = $_POST['password'];
$database = $_POST['database'];
$prefix = $_POST['prefix'];
$company = $_POST['company'];
$logo = $_POST['logo'];
$sitestatus = $_POST['sitestatus'];
if (empty($hostname)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$hostname = $_CONFIG['hostname'];
}
if (empty($username)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$username = $_CONFIG['username'];
}
if (empty($password)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$password = $_CONFIG['password'];
}
if (empty($database)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$database = $_CONFIG['database'];
}
if (empty($prefix)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$prefix = $_CONFIG['prefix'];
}
if (empty($company)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$company = $_CONFIG['company'];
}
if (empty($logo)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$logo = "https://upload.wikimedia.org/wikipedia/commons/3/33/Vanamo_Logo.png";
}
if (empty($sitestatus)) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$sitestatus = "Online";
}
$array = array(
'hostname' => $hostname,
'username' => $username,
'password' => $password,
'database' => $database,
'prefix' => $prefix,
'company' => $company,
'logo' => $logo,
'site_status' => $sitestatus,
'encoding' => 'ANSI'
);
write_php_ini($array, "../datafile.ini");
/*DO NOT EDIT UNDER THIS LINE! */
/* ==============================================================*/
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(TRUE);
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(TRUE)-$startTime) < 5));
//file was locked so now we can store information
if ($canWrite)
{ fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
header('?stap=2');
}
}
if (isset($_POST['datadb'])) {
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
$mysqli = @new mysqli ($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database']);
if (mysqli_connect_error()) {
echo '<p style="color: red;">Niet alle gegevens zijn goed ingevoerd. Probeer het opnieuw.</p>';
} else {
header('Location: ?stap=2');
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?=$headertitle?> - Configuratie</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel='stylesheet' id='buttons-css' href='paneel/assets/css/installation.button.css' type='text/css' media='all'>
<link rel='stylesheet' id='install-css' href='paneel/assets/css/installation.css' type='text/css' media='all'>
</head>
<body class="wp-core-ui">
<?=$title?>
<p><?=$subtitle?></p>
<?=$content?>
<p><?=$subcontent?>
<p><?=$extra?></p>
<p class="step"><?=$button?></p>
</body>
</html>
Gewijzigd op 29/12/2016 16:56:42 door - Rob -
Waarom haal je de data met parse_ini_file niet gewoon 1 keer op om het in een variabele op te slaan? Nu doe je per keer in je code bij alle statements.
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
$adminpass = password_hash($_CONFIG['adminpass'], DEFAULT_PASSWORD);
$adminuser = $_CONFIG['adminuser'];
$table = $_CONFIG['prefix']."users";
$sql = "INSERT INTO `$table` (`username`, `password`) VALUES ($adminuser, $adminpass)";
$mysqli = @new mysqli ($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database']);
if ($mysqli->query($sql) === TRUE) {
header('Location: ?stap=3');
}
$adminuser = $_CONFIG['adminuser'];
$table = $_CONFIG['prefix']."users";
$sql = "INSERT INTO `$table` (`username`, `password`) VALUES ($adminuser, $adminpass)";
$mysqli = @new mysqli ($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database']);
if ($mysqli->query($sql) === TRUE) {
header('Location: ?stap=3');
}
Ik heb nu deze query, maar hij voert hem niet goed uit. Ik weet niet waar het probleem ligt en ook niet hoe ik het moet oplossen.. De verbinding is correct, dat weet ik zeker. Ik heb wel een vermoeden wat er fout is. Hij pakt uit datafile.ini "Admin" met "" maar in de query moet het '' zijn.. en als ik de query met '' begin doet de query het niet.
dit is de datafile.ini
Gewijzigd op 29/12/2016 18:18:21 door - Rob -
Escapen met $mysqli->real_escape_string()
Dat werkt helaas niet, als ik var_dump() doe blijft het met "" dus ook in de sql
Hoe pas je het dan toe? Want $mysqli->real_escape_string() meot in de query gebruiken, en uiteraard moet new mysqli() al eerste uitgevoerd worden. Het beste voer je die bovenaan je script uit, nadat je de configuratie hebt geladen.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (isset($_POST['login'])) {
$prefix = $mysqli->real_escape_string($_CONFIG['prefix']);
$table = $prefix.'users';
$adminuser = $mysqli->real_escape_string($_CONFIG['adminuser']);
$adminpass = $mysqli->real_escape_string(password_hash($_CONFIG['adminpass'], PASSWORD_DEFAULT));
$adminemail = $mysqli->real_escape_string($_CONFIG['adminemail']);
$sql = "INSERT INTO `$table` (`username`, `password`, `email`) VALUES ('$adminuser', '$adminpass', '$adminemail')";
if ($mysqli->query($sql) === TRUE) {
header('Location: /');
exit();
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
header('Location: /');
exit();
}
$prefix = $mysqli->real_escape_string($_CONFIG['prefix']);
$table = $prefix.'users';
$adminuser = $mysqli->real_escape_string($_CONFIG['adminuser']);
$adminpass = $mysqli->real_escape_string(password_hash($_CONFIG['adminpass'], PASSWORD_DEFAULT));
$adminemail = $mysqli->real_escape_string($_CONFIG['adminemail']);
$sql = "INSERT INTO `$table` (`username`, `password`, `email`) VALUES ('$adminuser', '$adminpass', '$adminemail')";
if ($mysqli->query($sql) === TRUE) {
header('Location: /');
exit();
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
header('Location: /');
exit();
}
de voledige code:
Code (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
error_reporting(0);
session_start();
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
if ($_CONFIG['installation'] == 1) {
header('Location: /');
exit();
}
if ($_CONFIG['configuration'] == 0) {
header('Location: /configuration');
exit();
}
if (empty($_GET['stap'])) {
if ($_CONFIG['language'] == "nl") {
$content = '
<body class="wp-core-ui">
<h1>Welkom</h1>
<p>Welkom bij de vijf minuten installatieproces van het paneel. Vul gewoon de informatie hieronder in en u bent klaar om nieuwste community paneel te gebruiken.</p>
<h2>Benodigde informatie</h2>
<p>De volgende informatie invoeren. Geen zorgen, deze gegevens kunnen in een later stadium worden gewijzigd.</p>
<form id="setup" method="post" novalidate="novalidate">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="company">Bedrijfsnaam</label></th>
<td><input name="company" type="text" id="company" size="25" value="" required></td>
</tr>
<tr>
<th scope="row"><label for="adminuser">Gebruikersnaam</label></th>
<td>
<input name="adminuser" type="text" id="adminuser" size="25" value="">
<p>Gebruikersnamen mogen alleen alfanumerieke karakters, spaties, underscores, koppeltekens, punten en het @ symbool bevatten.</p>
</td>
</tr>
<tr class="form-field form-required user-pass1-wrap">
<th scope="row">
<label for="adminpass">
Wachtwoord </label>
</th>
<td>
<div class="password">
<input type="text" name="adminpass" id="adminpass" autocomplete="off" data-reveal="1" value="XlX6WZB@Fg7pe!JV47" required>
</div>
<p><span class="description important">
<strong>Belangrijk:</strong>
Dit wachtwoord is nodig om in te loggen. Zorg ervoor dat u het bewaard op een geheime locatie.</span></p>
</td>
</tr>
<tr>
<th scope="row"><label for="adminemail">Uw e-mailadres</label></th>
<td><input name="adminemail" type="adminemail" id="adminemail" size="25" value="" required>
<p>Controleer uw e-mailadres voordat u verder gaat.</p></td>
</tr>
<tr>
<tr>
<th scope="row"><label for="companylogo">Bedrijfslogo</label></th>
<td><input name="companylogo" type="text" id="companylogo" size="25" value="" required>
<p>Zorg voor een werkende link die transparant is.</p></td>
</tr>
</tr>
</tbody></table>
<p class="step"><input type="submit" name="Submit" id="submit" class="button button-large" value="Het paneel installeren"></p>
</form>
</body>
';
} else {
$content = '
<body class="wp-core-ui">
<h1>Welcome</h1>
<p>Welcome by the five minutes installationpreces for the panel. Just full in the information below and you are ready to use the neweest community panel.</p>
<h2>Needed information</h2>
<p>Full in the next information. Don'."''".'t worry, those details can be changed in another stadium.</p>
<form id="setup" method="post" novalidate="novalidate">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="company">Company name</label></th>
<td><input name="company" type="text" id="company" size="25" value="" required></td>
</tr>
<tr>
<th scope="row"><label for="adminuser">Username</label></th>
<td>
<input name="adminuser" type="text" id="adminuser" size="25" value="">
<p>
Usernames can only contain alphanumeric characters, spaces, underscores, hyphens, periods and the @ symbol.</p>
</td>
</tr>
<tr class="form-field form-required user-pass1-wrap">
<th scope="row">
<label for="adminpass">
Password </label>
</th>
<td>
<div class="password">
<input type="text" name="adminpass" id="adminpass" autocomplete="off" data-reveal="1" value="XlX6WZB@Fg7pe!JV47" required>
</div>
<p><span class="description important">
<strong>Important:</strong>
This password is required to log in. Make sure you are safe it in a secret location.</span></p>
</td>
</tr>
<tr>
<th scope="row"><label for="adminemail">Your email</label></th>
<td><input name="adminemail" type="adminemail" id="adminemail" size="25" value="" required>
<p>
Check your email before continuing.</p></td>
</tr>
<tr>
<tr>
<th scope="row"><label for="companylogo">Company logo</label></th>
<td><input name="companylogo" type="text" id="companylogo" size="25" value="" required>
<p>
Provide a working link that is transparent.</p></td>
</tr>
</tr>
</tbody></table>
<p class="step"><input type="submit" name="Submit" id="submit" class="button button-large" value="Install the panel"></p>
</form>
</body>
';
}
} elseif ($_GET['stap'] == 1) {
if ($_CONFIG['language'] == "nl") {
$content = '
<body class="wp-core-ui">
<h1>Gelukt!</h1>
<p>Het paneel is geïnstalleerd. Had je meer stappen verwacht? Sorry voor u teleur te stellen.</p>
<form method="post">
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="user">Gebruikersnaam</label></th>
<td>'.$_CONFIG["adminuser"].'</td>
</tr>
<tr>
<th scope="row"><label for="user">Wachtwoord</label></th>
<td><i>Je gekozen wachtwoord.</i></td>
</tr>
</tbody>
</table>
<input type="hidden" name="installation" value="1">
<p class="step"><input type="submit" name="login" id="submit" class="button button-large" value="Inloggen"></p>
</form>
</body>
';
} else {
$content = '
<body class="wp-core-ui">
<h1>Succes!</h1>
<p>The panel has been installed. Were you expecting more steps? Sorry to dissapoint you.</p>
<form method="post">
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="user">Username</label></th>
<td>'.$_CONFIG["adminuser"].'</td>
</tr>
<tr>
<th scope="row"><label for="user">Password</label></th>
<td><i>Your chosen password.</i></td>
</tr>
</tbody>
</table>
<input type="hidden" name="installation" value="1">
<p class="step"><input type="submit" name="login" id="submit" class="button button-large" value="Log in"></p>
</form>
</body>
';
}
}
if (isset($_POST['language'])) {
header('Location: ?stap=1');
}
if (empty($_POST['language'])) {
$_POST['language'] = $_CONFIG['language'];
}
if (empty($_POST['hostname'])) {
$_POST['hostname'] = $_CONFIG['hostname'];
}
if (empty($_POST['user'])) {
$_POST['user'] = $_CONFIG['username'];
}
if (empty($_POST['pass'])) {
$_POST['pass'] = $_CONFIG['password'];
}
if (empty($_POST['database'])) {
$_POST['database'] = $_CONFIG['database'];
}
if (empty($_POST['prefix'])) {
$_POST['prefix'] = $_CONFIG['prefix'];
}
if (empty($_POST['configuration'])) {
$_POST['configuration'] = $_CONFIG['configuration'];
}
if (empty($_POST['company'])) {
$_POST['company'] = $_CONFIG['company'];
}
if (empty($_POST['companylogo'])) {
$_POST['companylogo'] = $_CONFIG['companylogo'];
}
if (empty($_POST['adminuser'])) {
$_POST['adminuser'] = $_CONFIG['adminuser'];
}
if (empty($_POST['adminpass'])) {
$_POST['adminpass'] = $_CONFIG['adminpass'];
}
if (empty($_POST['adminemail'])) {
$_POST['adminemail'] = $_CONFIG['adminemail'];
}
if (empty($_POST['installation'])) {
$_POST['installation'] = $_CONFIG['installation'];
}
$array = array(
'language' => $_POST['language'],
'hostname' => $_POST['hostname'],
'username' => $_POST['user'],
'password' => $_POST['pass'],
'database' => $_POST['database'],
'prefix' => $_POST['prefix'],
'company' => $_POST['company'],
'companylogo' => $_POST['companylogo'],
'adminuser' => $_POST['adminuser'],
'adminpass' => $_POST['adminpass'],
'adminemail' => $_POST['adminemail'],
'configuration' => $_POST['configuration'],
'installation' => $_POST['installation'],
'encoding' => 'ANSI'
);
write_php_ini($array, $_SERVER["DOCUMENT_ROOT"] . "/../datafile.ini");
/*DO NOT EDIT UNDER THIS LINE! */
/* ==============================================================*/
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(TRUE);
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(TRUE)-$startTime) < 5));
//file was locked so now we can store information
if ($canWrite)
{ fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
header('?stap=');
}
}
if (isset($_POST['login'])) {
$prefix = $mysqli->real_escape_string($_CONFIG['prefix']);
$table = $prefix.'users';
$adminuser = $mysqli->real_escape_string($_CONFIG['adminuser']);
$adminpass = $mysqli->real_escape_string(password_hash($_CONFIG['adminpass'], PASSWORD_DEFAULT));
$adminemail = $mysqli->real_escape_string($_CONFIG['adminemail']);
$sql = "INSERT INTO `$table` (`username`, `password`, `email`) VALUES ('$adminuser', '$adminpass', '$adminemail')";
if ($mysqli->query($sql) === TRUE) {
header('Location: /');
exit();
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
header('Location: /');
exit();
}
if (isset($_POST['Submit'])) {
header('Location: ?stap=1');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Paneel - <?php if ($_CONFIG['language'] == "nl") { echo 'Installatie';} else { echo 'Installation';} ?></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel='stylesheet' id='buttons-css' href='paneel/assets/css/installation.button.css' type='text/css' media='all'>
<link rel='stylesheet' id='install-css' href='paneel/assets/css/installation.css' type='text/css' media='all'>
</head>
<?php
echo $content;
?>
</html>
bij fclose($fp); daaronder heb ik header('?stap='); gezet anders werd het ook wit scherm..?
error_reporting(0);
session_start();
$_CONFIG = parse_ini_file($_SERVER["DOCUMENT_ROOT"] . '/../datafile.ini');
if ($_CONFIG['installation'] == 1) {
header('Location: /');
exit();
}
if ($_CONFIG['configuration'] == 0) {
header('Location: /configuration');
exit();
}
if (empty($_GET['stap'])) {
if ($_CONFIG['language'] == "nl") {
$content = '
<body class="wp-core-ui">
<h1>Welkom</h1>
<p>Welkom bij de vijf minuten installatieproces van het paneel. Vul gewoon de informatie hieronder in en u bent klaar om nieuwste community paneel te gebruiken.</p>
<h2>Benodigde informatie</h2>
<p>De volgende informatie invoeren. Geen zorgen, deze gegevens kunnen in een later stadium worden gewijzigd.</p>
<form id="setup" method="post" novalidate="novalidate">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="company">Bedrijfsnaam</label></th>
<td><input name="company" type="text" id="company" size="25" value="" required></td>
</tr>
<tr>
<th scope="row"><label for="adminuser">Gebruikersnaam</label></th>
<td>
<input name="adminuser" type="text" id="adminuser" size="25" value="">
<p>Gebruikersnamen mogen alleen alfanumerieke karakters, spaties, underscores, koppeltekens, punten en het @ symbool bevatten.</p>
</td>
</tr>
<tr class="form-field form-required user-pass1-wrap">
<th scope="row">
<label for="adminpass">
Wachtwoord </label>
</th>
<td>
<div class="password">
<input type="text" name="adminpass" id="adminpass" autocomplete="off" data-reveal="1" value="XlX6WZB@Fg7pe!JV47" required>
</div>
<p><span class="description important">
<strong>Belangrijk:</strong>
Dit wachtwoord is nodig om in te loggen. Zorg ervoor dat u het bewaard op een geheime locatie.</span></p>
</td>
</tr>
<tr>
<th scope="row"><label for="adminemail">Uw e-mailadres</label></th>
<td><input name="adminemail" type="adminemail" id="adminemail" size="25" value="" required>
<p>Controleer uw e-mailadres voordat u verder gaat.</p></td>
</tr>
<tr>
<tr>
<th scope="row"><label for="companylogo">Bedrijfslogo</label></th>
<td><input name="companylogo" type="text" id="companylogo" size="25" value="" required>
<p>Zorg voor een werkende link die transparant is.</p></td>
</tr>
</tr>
</tbody></table>
<p class="step"><input type="submit" name="Submit" id="submit" class="button button-large" value="Het paneel installeren"></p>
</form>
</body>
';
} else {
$content = '
<body class="wp-core-ui">
<h1>Welcome</h1>
<p>Welcome by the five minutes installationpreces for the panel. Just full in the information below and you are ready to use the neweest community panel.</p>
<h2>Needed information</h2>
<p>Full in the next information. Don'."''".'t worry, those details can be changed in another stadium.</p>
<form id="setup" method="post" novalidate="novalidate">
<table class="form-table">
<tbody><tr>
<th scope="row"><label for="company">Company name</label></th>
<td><input name="company" type="text" id="company" size="25" value="" required></td>
</tr>
<tr>
<th scope="row"><label for="adminuser">Username</label></th>
<td>
<input name="adminuser" type="text" id="adminuser" size="25" value="">
<p>
Usernames can only contain alphanumeric characters, spaces, underscores, hyphens, periods and the @ symbol.</p>
</td>
</tr>
<tr class="form-field form-required user-pass1-wrap">
<th scope="row">
<label for="adminpass">
Password </label>
</th>
<td>
<div class="password">
<input type="text" name="adminpass" id="adminpass" autocomplete="off" data-reveal="1" value="XlX6WZB@Fg7pe!JV47" required>
</div>
<p><span class="description important">
<strong>Important:</strong>
This password is required to log in. Make sure you are safe it in a secret location.</span></p>
</td>
</tr>
<tr>
<th scope="row"><label for="adminemail">Your email</label></th>
<td><input name="adminemail" type="adminemail" id="adminemail" size="25" value="" required>
<p>
Check your email before continuing.</p></td>
</tr>
<tr>
<tr>
<th scope="row"><label for="companylogo">Company logo</label></th>
<td><input name="companylogo" type="text" id="companylogo" size="25" value="" required>
<p>
Provide a working link that is transparent.</p></td>
</tr>
</tr>
</tbody></table>
<p class="step"><input type="submit" name="Submit" id="submit" class="button button-large" value="Install the panel"></p>
</form>
</body>
';
}
} elseif ($_GET['stap'] == 1) {
if ($_CONFIG['language'] == "nl") {
$content = '
<body class="wp-core-ui">
<h1>Gelukt!</h1>
<p>Het paneel is geïnstalleerd. Had je meer stappen verwacht? Sorry voor u teleur te stellen.</p>
<form method="post">
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="user">Gebruikersnaam</label></th>
<td>'.$_CONFIG["adminuser"].'</td>
</tr>
<tr>
<th scope="row"><label for="user">Wachtwoord</label></th>
<td><i>Je gekozen wachtwoord.</i></td>
</tr>
</tbody>
</table>
<input type="hidden" name="installation" value="1">
<p class="step"><input type="submit" name="login" id="submit" class="button button-large" value="Inloggen"></p>
</form>
</body>
';
} else {
$content = '
<body class="wp-core-ui">
<h1>Succes!</h1>
<p>The panel has been installed. Were you expecting more steps? Sorry to dissapoint you.</p>
<form method="post">
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="user">Username</label></th>
<td>'.$_CONFIG["adminuser"].'</td>
</tr>
<tr>
<th scope="row"><label for="user">Password</label></th>
<td><i>Your chosen password.</i></td>
</tr>
</tbody>
</table>
<input type="hidden" name="installation" value="1">
<p class="step"><input type="submit" name="login" id="submit" class="button button-large" value="Log in"></p>
</form>
</body>
';
}
}
if (isset($_POST['language'])) {
header('Location: ?stap=1');
}
if (empty($_POST['language'])) {
$_POST['language'] = $_CONFIG['language'];
}
if (empty($_POST['hostname'])) {
$_POST['hostname'] = $_CONFIG['hostname'];
}
if (empty($_POST['user'])) {
$_POST['user'] = $_CONFIG['username'];
}
if (empty($_POST['pass'])) {
$_POST['pass'] = $_CONFIG['password'];
}
if (empty($_POST['database'])) {
$_POST['database'] = $_CONFIG['database'];
}
if (empty($_POST['prefix'])) {
$_POST['prefix'] = $_CONFIG['prefix'];
}
if (empty($_POST['configuration'])) {
$_POST['configuration'] = $_CONFIG['configuration'];
}
if (empty($_POST['company'])) {
$_POST['company'] = $_CONFIG['company'];
}
if (empty($_POST['companylogo'])) {
$_POST['companylogo'] = $_CONFIG['companylogo'];
}
if (empty($_POST['adminuser'])) {
$_POST['adminuser'] = $_CONFIG['adminuser'];
}
if (empty($_POST['adminpass'])) {
$_POST['adminpass'] = $_CONFIG['adminpass'];
}
if (empty($_POST['adminemail'])) {
$_POST['adminemail'] = $_CONFIG['adminemail'];
}
if (empty($_POST['installation'])) {
$_POST['installation'] = $_CONFIG['installation'];
}
$array = array(
'language' => $_POST['language'],
'hostname' => $_POST['hostname'],
'username' => $_POST['user'],
'password' => $_POST['pass'],
'database' => $_POST['database'],
'prefix' => $_POST['prefix'],
'company' => $_POST['company'],
'companylogo' => $_POST['companylogo'],
'adminuser' => $_POST['adminuser'],
'adminpass' => $_POST['adminpass'],
'adminemail' => $_POST['adminemail'],
'configuration' => $_POST['configuration'],
'installation' => $_POST['installation'],
'encoding' => 'ANSI'
);
write_php_ini($array, $_SERVER["DOCUMENT_ROOT"] . "/../datafile.ini");
/*DO NOT EDIT UNDER THIS LINE! */
/* ==============================================================*/
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(TRUE);
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(TRUE)-$startTime) < 5));
//file was locked so now we can store information
if ($canWrite)
{ fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
header('?stap=');
}
}
if (isset($_POST['login'])) {
$prefix = $mysqli->real_escape_string($_CONFIG['prefix']);
$table = $prefix.'users';
$adminuser = $mysqli->real_escape_string($_CONFIG['adminuser']);
$adminpass = $mysqli->real_escape_string(password_hash($_CONFIG['adminpass'], PASSWORD_DEFAULT));
$adminemail = $mysqli->real_escape_string($_CONFIG['adminemail']);
$sql = "INSERT INTO `$table` (`username`, `password`, `email`) VALUES ('$adminuser', '$adminpass', '$adminemail')";
if ($mysqli->query($sql) === TRUE) {
header('Location: /');
exit();
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
header('Location: /');
exit();
}
if (isset($_POST['Submit'])) {
header('Location: ?stap=1');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Paneel - <?php if ($_CONFIG['language'] == "nl") { echo 'Installatie';} else { echo 'Installation';} ?></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel='stylesheet' id='buttons-css' href='paneel/assets/css/installation.button.css' type='text/css' media='all'>
<link rel='stylesheet' id='install-css' href='paneel/assets/css/installation.css' type='text/css' media='all'>
</head>
<?php
echo $content;
?>
</html>
bij fclose($fp); daaronder heb ik header('?stap='); gezet anders werd het ook wit scherm..?
Kan je je code even aanpassen naar relevante code i.p.v. +/- 300 regels? En kan je dan ook vertellen wat je aangepast hebt, en wat er fout gaat?
Quote:
Waarom pas je die safefilerewrite() aan met een redirect? Dat lijkt mij niet het juiste onderdeel van deze functie.
anders werkt het niet, dan wordt het wit scherm..
Toevoeging op 03/01/2017 14:43:36:
Verder heb ik niks daaraan aangepast
Toevoeging op 03/01/2017 14:44:07:
en wat er fout gaat heb ik geen idee, hij geeft geen errors.
Toevoeging op 03/01/2017 14:52:34:
O SORRY!! O god ik was vergeten dat ik error_reporting(0) had -_- sorry!