Multiple pages in 1 page
Ik ben nu al een tijdje bezig met multiple forms zodat mijn gebruikers informatie naar mijn server kunnen sturen via een .ini bestand.
Ik probeer om mijn 3 pagina's met forms in 1 script te plaatsen :
start.php
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
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
<?php
$file = 'user01.ini';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = '';
foreach($_POST AS $name=>$value) {
$data .= $name . '=' . $value .PHP_EOL;
}
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo 'Saved in <a href="' . $file . '">' . $file . '</a>';
} else {
echo 'Failed';
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
?>
<form method="POST">
<label>IP</label>
<input type="numbers" name="ip" value="<?php echo (isset($ini['ip']) ? $ini['ip'] : '127.0.0.1'); ?>" /><br />
<label>Gebruikers</label>
<input type="number" name="gebruikers" value="<?php echo (isset($ini['gebruikers']) ? $ini['gebruikers'] : '10'); ?>" /><br />
<label>Website</label>
<input type="text" name="website" value="<?php echo (isset($ini['website']) ? $ini['website'] : 'http://'); ?>" /><br />
<button>Start</button>
</form>
$file = 'user01.ini';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = '';
foreach($_POST AS $name=>$value) {
$data .= $name . '=' . $value .PHP_EOL;
}
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo 'Saved in <a href="' . $file . '">' . $file . '</a>';
} else {
echo 'Failed';
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
?>
<form method="POST">
<label>IP</label>
<input type="numbers" name="ip" value="<?php echo (isset($ini['ip']) ? $ini['ip'] : '127.0.0.1'); ?>" /><br />
<label>Gebruikers</label>
<input type="number" name="gebruikers" value="<?php echo (isset($ini['gebruikers']) ? $ini['gebruikers'] : '10'); ?>" /><br />
<label>Website</label>
<input type="text" name="website" value="<?php echo (isset($ini['website']) ? $ini['website'] : 'http://'); ?>" /><br />
<button>Start</button>
</form>
toevoegen.php
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
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
<?php
$file = fopen("user01.ini","r");
if(!file)
{
echo("ERROR:cant open file");
}
else
{
$buff = fread ($file,filesize("user01.ini"));
print $buff;
}
$file = 'user01.ini';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = '';
foreach($_POST AS $name=>$value) {
$data .= $name . '=' . $value .PHP_EOL;
}
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo 'Saved in <a href="' . $file . '">' . $file . '</a>';
} else {
echo 'Failed';
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
?>
<form method="POST">
<label>Gebruikers Toevoegen</label>
<input type="number" name="addgebruikers" value="<?php echo (isset($ini['addgebruikers']) ? $ini['addgebruikers'] : '10'); ?>" /><br />
<button>Toevoegen</button>
<button>Stop</button>
</form>
$file = fopen("user01.ini","r");
if(!file)
{
echo("ERROR:cant open file");
}
else
{
$buff = fread ($file,filesize("user01.ini"));
print $buff;
}
$file = 'user01.ini';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = '';
foreach($_POST AS $name=>$value) {
$data .= $name . '=' . $value .PHP_EOL;
}
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo 'Saved in <a href="' . $file . '">' . $file . '</a>';
} else {
echo 'Failed';
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
?>
<form method="POST">
<label>Gebruikers Toevoegen</label>
<input type="number" name="addgebruikers" value="<?php echo (isset($ini['addgebruikers']) ? $ini['addgebruikers'] : '10'); ?>" /><br />
<button>Toevoegen</button>
<button>Stop</button>
</form>
stop.php
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
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
<?php
$file = 'user01.ini';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = '';
foreach($_POST AS $name=>$value) {
$data .= $name . '=' . $value .PHP_EOL;
}
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo 'Saved in <a href="' . $file . '">' . $file . '</a>';
} else {
echo 'Failed';
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
?>
<form method="POST">
<label>Server has stopped</label><br>
<label>IP</label>
<input type="numbers" name="ip" value="<?php echo (isset($ini['ip']) ? $ini['ip'] : '127.0.0.1'); ?>" /><br />
<label>Gebruikers</label>
<input type="number" name="gebruikers" value="<?php echo (isset($ini['gebruikers']) ? $ini['gebruikers'] : '10'); ?>" /><br />
<label>Website</label>
<input type="text" name="website" value="<?php echo (isset($ini['website']) ? $ini['website'] : 'http://'); ?>" /><br />
<button>Start</button>
</form>
$file = 'user01.ini';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = '';
foreach($_POST AS $name=>$value) {
$data .= $name . '=' . $value .PHP_EOL;
}
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo 'Saved in <a href="' . $file . '">' . $file . '</a>';
} else {
echo 'Failed';
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
?>
<form method="POST">
<label>Server has stopped</label><br>
<label>IP</label>
<input type="numbers" name="ip" value="<?php echo (isset($ini['ip']) ? $ini['ip'] : '127.0.0.1'); ?>" /><br />
<label>Gebruikers</label>
<input type="number" name="gebruikers" value="<?php echo (isset($ini['gebruikers']) ? $ini['gebruikers'] : '10'); ?>" /><br />
<label>Website</label>
<input type="text" name="website" value="<?php echo (isset($ini['website']) ? $ini['website'] : 'http://'); ?>" /><br />
<button>Start</button>
</form>
Is het mogelijk om alles in 1 script te plaatsen?
start.php
start > toevoegen.php (index.php?p=toevoegen)
toevoegen.php
toevoegen > toevoegen.php (index.php?p=toevoegen)
stop > stop.php (index.php?p=stop)
stop.php
start > start.php (index.php?p=start)
Alvast bedankt voor het lezen!
PS : is het mogelijk om er 1 script van te maken met echo's ?
Gewijzigd op 03/03/2014 11:33:26 door Patrick B
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
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
<?php
$file = 'config.ini';
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['btn_start'],$_POST['servername'],$_POST['users'])) {
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=running'.PHP_EOL;
$data .= 'name=' . htmlentities($_POST['servername']).PHP_EOL;
$data .= 'users=' . htmlentities($_POST['users']).PHP_EOL;
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo '<p>Saved in <a href="' . $file . '">' . $file . '</a></p>';
} else {
echo '<p>Failed</p>';
}
} else if(isset($_POST['btn_add'],$_POST['add_users']) && $_POST['add_users'] > 0) {
$users = (int)$ini['users'] + (int)htmlentities($_POST['add_users']);
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=stopped'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $users.PHP_EOL;
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo '<p>Saved in <a href="' . $file . '">' . $file . '</a></p>';
} else {
echo '<p>Failed</p>';
}
} else if(isset($_POST['btn_stop'])) {
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=stopped'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $ini['users'].PHP_EOL;
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo '<p>Saved in <a href="' . $file . '">' . $file . '</a></p>';
} else {
echo '<p>Failed</p>';
}
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
echo '<p>Server is ' . $ini['status'] . '</p>';
}
if(isset($_GET['add_stop'])) {
?>
<form method="POST">
<label>Users</label>
<input type="number" name="add_users" value="0" /><br />
<button type="submit" name="btn_add">Add</button>
<button type="submit" name="btn_stop">Stop</button>
</form>
<?php
} else {
?>
<form method="POST">
<label>Servername</label>
<input type="numbers" name="servername" value="<?php echo (isset($ini['name']) ? $ini['name'] : ''); ?>" /><br />
<label>Users</label>
<input type="number" name="users" value="<?php echo (isset($ini['users']) ? $ini['users'] : '10'); ?>" /><br />
<button type="submit" name="btn_start">Start</button>
</form>
<?php
}
echo '<p><a href="' . $_SERVER['SCRIPT_NAME'] . '">Start and config server</a>
<a href="' . $_SERVER['SCRIPT_NAME'] . '?add_stop">Add users or stop server</a></p>';
?>
$file = 'config.ini';
if(file_exists($file)) {
$ini = parse_ini_file($file);
}
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['btn_start'],$_POST['servername'],$_POST['users'])) {
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=running'.PHP_EOL;
$data .= 'name=' . htmlentities($_POST['servername']).PHP_EOL;
$data .= 'users=' . htmlentities($_POST['users']).PHP_EOL;
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo '<p>Saved in <a href="' . $file . '">' . $file . '</a></p>';
} else {
echo '<p>Failed</p>';
}
} else if(isset($_POST['btn_add'],$_POST['add_users']) && $_POST['add_users'] > 0) {
$users = (int)$ini['users'] + (int)htmlentities($_POST['add_users']);
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=stopped'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $users.PHP_EOL;
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo '<p>Saved in <a href="' . $file . '">' . $file . '</a></p>';
} else {
echo '<p>Failed</p>';
}
} else if(isset($_POST['btn_stop'])) {
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=stopped'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $ini['users'].PHP_EOL;
file_put_contents($file, $data, LOCK_EX);
if(file_exists($file)) {
echo '<p>Saved in <a href="' . $file . '">' . $file . '</a></p>';
} else {
echo '<p>Failed</p>';
}
}
}
if(file_exists($file)) {
$ini = parse_ini_file($file);
echo '<p>Server is ' . $ini['status'] . '</p>';
}
if(isset($_GET['add_stop'])) {
?>
<form method="POST">
<label>Users</label>
<input type="number" name="add_users" value="0" /><br />
<button type="submit" name="btn_add">Add</button>
<button type="submit" name="btn_stop">Stop</button>
</form>
<?php
} else {
?>
<form method="POST">
<label>Servername</label>
<input type="numbers" name="servername" value="<?php echo (isset($ini['name']) ? $ini['name'] : ''); ?>" /><br />
<label>Users</label>
<input type="number" name="users" value="<?php echo (isset($ini['users']) ? $ini['users'] : '10'); ?>" /><br />
<button type="submit" name="btn_start">Start</button>
</form>
<?php
}
echo '<p><a href="' . $_SERVER['SCRIPT_NAME'] . '">Start and config server</a>
<a href="' . $_SERVER['SCRIPT_NAME'] . '?add_stop">Add users or stop server</a></p>';
?>
Gewijzigd op 03/03/2014 09:03:33 door Michael -
Waar heb je het over? Hij wil meerdere formulieren om een bestand aan te passen. Heeft niks met include te maken.
Werkt perfect, nogmaals bedankt!
Top!
Edit : gevonden!
Code (php)
1
2
3
4
5
6
2
3
4
5
6
} else if(isset($_POST['btn_add'],$_POST['add_users']) && $_POST['add_users'] > 0) {
$users = (int)$ini['users'] + (int)htmlentities($_POST['add_users']);
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=stopped'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $users.PHP_EOL;
$users = (int)$ini['users'] + (int)htmlentities($_POST['add_users']);
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=stopped'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $users.PHP_EOL;
naar
Code (php)
1
2
3
4
5
6
2
3
4
5
6
} else if(isset($_POST['btn_add'],$_POST['add_users']) && $_POST['add_users'] > 0) {
$users = (int)$ini['users'] + (int)htmlentities($_POST['add_users']);
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=running'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $users.PHP_EOL;
$users = (int)$ini['users'] + (int)htmlentities($_POST['add_users']);
$data = '[Configuration file]'.PHP_EOL;
$data .= 'status=running'.PHP_EOL;
$data .= 'name=' . $ini['name'].PHP_EOL;
$data .= 'users=' . $users.PHP_EOL;
Gewijzigd op 03/03/2014 12:15:21 door Patrick B
Sorry knip en plak foutje ;)
Ik krijg
niet in de button verwerkt
PS : Sorry voor domme vragen maar ik kom van C# en php is een nieuw boek voor mij, ik waardeer de hulp enorm die ik hier krijg!
Gewijzigd op 03/03/2014 15:10:27 door Patrick B
Toevoeging op 03/03/2014 15:17:57:
Als je bij add/stop ook weer terug wilt verander je die andere form in
Gewijzigd op 03/03/2014 15:19:28 door Michael -
Werkt perfect!