Pagina schrijft cfg bestand niet
Bij het openen wordt het huidige bestand ingelezen [gaat goed]
Wijzigingen moeten in dit bestand worden weggeschreven [gaat niet goed, er blijft een leeg bestand over]
Waar zit ik fout? (ik snap niet waarom alles hieronder niet als 1 code wordt weergegeven, voor de duidelijkheid: het is dus 1 bestand.)
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
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
<!DOCTYPE html>
<?php
$myFile = "redirect/underconstruction.cfg";
$fh = fopen($myFile, 'r');
while(!feof($fh))
{
$data[] = fgets($fh);
}
?>
<?php
if(isset($_POST['submit']))
$SiteT = $_POST['sitetitle'];
$Head1 = $_POST['header1'];
$Head2 = $_POST['header2'];
$Msg1 = $_POST['message1'];
$Msg2 = $_POST['message2'];
$Msg3 = $_POST['message3'];
$Msg4 = $_POST['message4'];
$Msg5 = $_POST['message5'];
$FtUrl = $_POST['footurl'];
$file = fopen("redirect/underconstruction.cfg","w+") or die ("file not open...");
$s = $SiteT."\r\n".
$Head1."\r\n".
$Head2."\r\n".
$Msg1."\r\n".
$Msg2."\r\n".
$Msg3."\r\n".
$Msg4."\r\n".
$Msg5."\r\n".
$FtUrl;
fputs($file,$s) or die("Data not written.");
fclose($file);
?>
<html lang="nl-NL">
<head>
<title>Moving Page Admin</title>
<style type="text/css">
html {
height: 100%;
background: #499bea;
background: -moz-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, #499bea), color-stop(100%, #08396e));
background: -webkit-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -o-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -ms-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: radial-gradient(ellipse at center, #499bea 0%, #08396e 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#499bea', endColorstr='#08396e', GradientType=1 );
background-image:"background.jpg";
}
#maindiv{
border: medium solid #b7b7b7;
background-color: #eaeaea;
max-width: 750px;
margin: 0 auto;
padding: 10px;
}
</style>
</head>
<body>
<div id="maindiv">
<h1><strong>Moving Page Admin</strong></h1>
<p><span style="font-size:16px"><em><strong>Site Title</strong></em></span><br />
<form action="#" method="post">
<input name="sitetitle" style="width: 100%;" type="text" value="<?php echo $data[1];?>" /></p>
<p><span style="font-size:16px"><strong><em>Header Text</em></strong></span><br />
<input name="header1" style="width: 100%;" type="text" value="<?php echo $data[3];?>" /><br />
<input name="header2" style="width: 100%;" type="text" value="<?php echo $data[4];?>" /></p>
<p> </p>
<p><strong><em><span style="font-size:16px">Message Text</span></em></strong><br />
(Use <strong><em><span style="color:#800080"><span></span></span></em></strong> to highlight text,<strong><em><span style="color:#800080"> <br></span></em></strong> for a linebreak.)<br />
<input name="message1" style="width: 100%;" type="text" value="<?php echo $data[6];?>" /><br />
<input name="message2" style="width: 100%;" type="text" value="<?php echo $data[7];?>" /><br />
<input name="message3" style="width: 100%;" type="text" value="<?php echo $data[8];?>" /><br />
<input name="message4" style="width: 100%;" type="text" value="<?php echo $data[9];?>;" /><br />
<input name="message5" style="width: 100%;" type="text" value="<?php echo $data[10];?>" /></p>
<p> </p>
<p><span style="font-size:16px"><em><strong>Footer-URL</strong></em></span><br />
<input name="footurl" style="width: 50%;" type="url" value="<?php echo $data[12];?>" /></p>
<p><input name="submit" type="submit" value="Save" /></p>
</div>
</form>
</body>
</html>
<?php
$myFile = "redirect/underconstruction.cfg";
$fh = fopen($myFile, 'r');
while(!feof($fh))
{
$data[] = fgets($fh);
}
?>
<?php
if(isset($_POST['submit']))
$SiteT = $_POST['sitetitle'];
$Head1 = $_POST['header1'];
$Head2 = $_POST['header2'];
$Msg1 = $_POST['message1'];
$Msg2 = $_POST['message2'];
$Msg3 = $_POST['message3'];
$Msg4 = $_POST['message4'];
$Msg5 = $_POST['message5'];
$FtUrl = $_POST['footurl'];
$file = fopen("redirect/underconstruction.cfg","w+") or die ("file not open...");
$s = $SiteT."\r\n".
$Head1."\r\n".
$Head2."\r\n".
$Msg1."\r\n".
$Msg2."\r\n".
$Msg3."\r\n".
$Msg4."\r\n".
$Msg5."\r\n".
$FtUrl;
fputs($file,$s) or die("Data not written.");
fclose($file);
?>
<html lang="nl-NL">
<head>
<title>Moving Page Admin</title>
<style type="text/css">
html {
height: 100%;
background: #499bea;
background: -moz-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, #499bea), color-stop(100%, #08396e));
background: -webkit-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -o-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -ms-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: radial-gradient(ellipse at center, #499bea 0%, #08396e 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#499bea', endColorstr='#08396e', GradientType=1 );
background-image:"background.jpg";
}
#maindiv{
border: medium solid #b7b7b7;
background-color: #eaeaea;
max-width: 750px;
margin: 0 auto;
padding: 10px;
}
</style>
</head>
<body>
<div id="maindiv">
<h1><strong>Moving Page Admin</strong></h1>
<p><span style="font-size:16px"><em><strong>Site Title</strong></em></span><br />
<form action="#" method="post">
<input name="sitetitle" style="width: 100%;" type="text" value="<?php echo $data[1];?>" /></p>
<p><span style="font-size:16px"><strong><em>Header Text</em></strong></span><br />
<input name="header1" style="width: 100%;" type="text" value="<?php echo $data[3];?>" /><br />
<input name="header2" style="width: 100%;" type="text" value="<?php echo $data[4];?>" /></p>
<p> </p>
<p><strong><em><span style="font-size:16px">Message Text</span></em></strong><br />
(Use <strong><em><span style="color:#800080"><span></span></span></em></strong> to highlight text,<strong><em><span style="color:#800080"> <br></span></em></strong> for a linebreak.)<br />
<input name="message1" style="width: 100%;" type="text" value="<?php echo $data[6];?>" /><br />
<input name="message2" style="width: 100%;" type="text" value="<?php echo $data[7];?>" /><br />
<input name="message3" style="width: 100%;" type="text" value="<?php echo $data[8];?>" /><br />
<input name="message4" style="width: 100%;" type="text" value="<?php echo $data[9];?>;" /><br />
<input name="message5" style="width: 100%;" type="text" value="<?php echo $data[10];?>" /></p>
<p> </p>
<p><span style="font-size:16px"><em><strong>Footer-URL</strong></em></span><br />
<input name="footurl" style="width: 50%;" type="url" value="<?php echo $data[12];?>" /></p>
<p><input name="submit" type="submit" value="Save" /></p>
</div>
</form>
</body>
</html>
Edit:
Ik heb code-tags geplaatst. Gelieve dit in het vervolg zelf toe te voegen aan je bericht.
Zie ook: Veel gestelde vragen: Welke UBB-codes kan ik gebruiken.
Zie ook: Veel gestelde vragen: Welke UBB-codes kan ik gebruiken.
Gewijzigd op 13/03/2019 15:56:49 door - Ariën -
Je kan trouwens ook file_put_contents gebruiken.
De genummerde variabelen $Msg1 etc.. zijn best onnodig. Je hebt immers al je $_POST['message1'] (etc..) variabelen die je kan gebruiken. Dus waarom zou je de data dubbel aanmaken?
- geen fclose na het inlezen (dus zo rond regel 10 invoegen)
- waarom PHP sluit en meteen weer open tags regel 10..12?
- waarom gebruik je op regel 25 niet ook $myfile?
- zitten al die waarden wel in de POST, of bestaat je "lege" bestand uit enkel "\r\n"-en?
- je gebruikt in je form nu $data[x], maar die bevatten na het opslaan altijd de oude waarden
Ik weet niet precies wat je doel is, maar het opslaan van data kan beter in een ini, json, of iets dergelijks.
PHP kent ook niet de term cfg (zover ik weet) zoals bijv. Python dat wel kent.
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
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
<?php
$myFile = "redirect/underconstruction.cfg";
if($_SERVER['REQUEST_METHOD'] == "POST") {
$s = $_POST['sitetitle']."\r\n".
$_POST['header1']."\r\n".
$_POST['header2']."\r\n".
$_POST['message1']."\r\n".
$_POST['message2']."\r\n".
$_POST['message3']."\r\n".
$_POST['message4']."\r\n".
$_POST['message5']."\r\n".
$_POST['footurl']."\r\n";
file_put_contents($myFile, $s, LOCK_EX);
}
if(file_exists($myFile)) {
$data = explode("\r\n", file_get_contents( $myFile ) );
}
?>
<!DOCTYPE html>
<html lang="nl-NL">
<head>
<title>Moving Page Admin</title>
<style type="text/css">
html {
height: 100%;
background: #499bea;
background: -moz-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, #499bea), color-stop(100%, #08396e));
background: -webkit-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -o-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -ms-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: radial-gradient(ellipse at center, #499bea 0%, #08396e 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#499bea', endColorstr='#08396e', GradientType=1 );
background-image:"background.jpg";
}
#maindiv{
border: medium solid #b7b7b7;
background-color: #eaeaea;
max-width: 750px;
margin: 0 auto;
padding: 10px;
}
</style>
</head>
<body>
<div id="maindiv">
<h1><strong>Moving Page Admin</strong></h1>
<p><span style="font-size:16px"><em><strong>Site Title</strong></em></span><br />
<form method="post">
<input name="sitetitle" style="width: 100%;" type="text" value="<?php echo (isset($data[0]) ? $data[0] : ''); ?>" /></p>
<p><span style="font-size:16px"><strong><em>Header Text</em></strong></span><br />
<input name="header1" style="width: 100%;" type="text" value="<?php echo (isset($data[1]) ? $data[1] : ''); ?>" /><br />
<input name="header2" style="width: 100%;" type="text" value="<?php echo (isset($data[2]) ? $data[2] : ''); ?>" /></p>
<p> </p>
<p><strong><em><span style="font-size:16px">Message Text</span></em></strong><br />
(Use <strong><em><span style="color:#800080"><span></span></span></em></strong> to highlight text,<strong><em><span style="color:#800080"> <br></span></em></strong> for a linebreak.)<br />
<input name="message1" style="width: 100%;" type="text" value="<?php echo (isset($data[3]) ? $data[3] : ''); ?>" /><br />
<input name="message2" style="width: 100%;" type="text" value="<?php echo (isset($data[4]) ? $data[4] : ''); ?>" /><br />
<input name="message3" style="width: 100%;" type="text" value="<?php echo (isset($data[5]) ? $data[5] : ''); ?>" /><br />
<input name="message4" style="width: 100%;" type="text" value="<?php echo (isset($data[6]) ? $data[6] : ''); ?>" /><br />
<input name="message5" style="width: 100%;" type="text" value="<?php echo (isset($data[7]) ? $data[7] : ''); ?>" /></p>
<p> </p>
<p><span style="font-size:16px"><em><strong>Footer-URL</strong></em></span><br />
<input name="footurl" style="width: 50%;" type="url" value="<?php echo (isset($data[8]) ? $data[8] : ''); ?>" /></p>
<p><input name="submit" type="submit" value="Save" /></p>
</div>
</form>
</body>
</html>
$myFile = "redirect/underconstruction.cfg";
if($_SERVER['REQUEST_METHOD'] == "POST") {
$s = $_POST['sitetitle']."\r\n".
$_POST['header1']."\r\n".
$_POST['header2']."\r\n".
$_POST['message1']."\r\n".
$_POST['message2']."\r\n".
$_POST['message3']."\r\n".
$_POST['message4']."\r\n".
$_POST['message5']."\r\n".
$_POST['footurl']."\r\n";
file_put_contents($myFile, $s, LOCK_EX);
}
if(file_exists($myFile)) {
$data = explode("\r\n", file_get_contents( $myFile ) );
}
?>
<!DOCTYPE html>
<html lang="nl-NL">
<head>
<title>Moving Page Admin</title>
<style type="text/css">
html {
height: 100%;
background: #499bea;
background: -moz-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, #499bea), color-stop(100%, #08396e));
background: -webkit-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -o-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: -ms-radial-gradient(center, ellipse cover, #499bea 0%, #08396e 100%);
background: radial-gradient(ellipse at center, #499bea 0%, #08396e 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#499bea', endColorstr='#08396e', GradientType=1 );
background-image:"background.jpg";
}
#maindiv{
border: medium solid #b7b7b7;
background-color: #eaeaea;
max-width: 750px;
margin: 0 auto;
padding: 10px;
}
</style>
</head>
<body>
<div id="maindiv">
<h1><strong>Moving Page Admin</strong></h1>
<p><span style="font-size:16px"><em><strong>Site Title</strong></em></span><br />
<form method="post">
<input name="sitetitle" style="width: 100%;" type="text" value="<?php echo (isset($data[0]) ? $data[0] : ''); ?>" /></p>
<p><span style="font-size:16px"><strong><em>Header Text</em></strong></span><br />
<input name="header1" style="width: 100%;" type="text" value="<?php echo (isset($data[1]) ? $data[1] : ''); ?>" /><br />
<input name="header2" style="width: 100%;" type="text" value="<?php echo (isset($data[2]) ? $data[2] : ''); ?>" /></p>
<p> </p>
<p><strong><em><span style="font-size:16px">Message Text</span></em></strong><br />
(Use <strong><em><span style="color:#800080"><span></span></span></em></strong> to highlight text,<strong><em><span style="color:#800080"> <br></span></em></strong> for a linebreak.)<br />
<input name="message1" style="width: 100%;" type="text" value="<?php echo (isset($data[3]) ? $data[3] : ''); ?>" /><br />
<input name="message2" style="width: 100%;" type="text" value="<?php echo (isset($data[4]) ? $data[4] : ''); ?>" /><br />
<input name="message3" style="width: 100%;" type="text" value="<?php echo (isset($data[5]) ? $data[5] : ''); ?>" /><br />
<input name="message4" style="width: 100%;" type="text" value="<?php echo (isset($data[6]) ? $data[6] : ''); ?>" /><br />
<input name="message5" style="width: 100%;" type="text" value="<?php echo (isset($data[7]) ? $data[7] : ''); ?>" /></p>
<p> </p>
<p><span style="font-size:16px"><em><strong>Footer-URL</strong></em></span><br />
<input name="footurl" style="width: 50%;" type="url" value="<?php echo (isset($data[8]) ? $data[8] : ''); ?>" /></p>
<p><input name="submit" type="submit" value="Save" /></p>
</div>
</form>
</body>
</html>
Gewijzigd op 13/03/2019 19:40:17 door Michael -