Re: Die üblichen Übungen

<?php
session_start ();
?>

<form method="POST" action="./form20240220.php">
<input type="text" name="2024022001"></input>
<input type="submit">
</form>

<?php
echo session_id () . "<br>n";

echo \$_POST ["2024022001"] . "<br>n";
echo \$_COOKIE ["2024022002"] . "<br>n";
echo \$_COOKIE ["2024022003"] . "<br>n";

session_destroy ();
?>

Jetzt kommt der Aufruf über den Browser und als HTTP-Request per telnet

Image Screenshot_20240220_174132

So, jetzt kommt der HTTP-Request.

POST http://localhost/mysql20240217/20240220/form20240220.php HTTP/1.1
host: localhost
Cookie: 2024022002=Hallo Welt
Content-Type: application/x-www-form-urlencoded
Content-Length: 22

2024022001=Super Sache

Trying ::1...
Connected to localhost.
Escape character is '\^]'.
HTTP/1.1 200 OK
Date: Tue, 20 Feb 2024 16:47:34 GMT
Server: Apache/2.4.57 (Debian)
Set-Cookie: PHPSESSID=cs2gqv5bm5r7et0e6h8dh907pb; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 194
Content-Type: text/html; charset=UTF-8

<form method="POST" action="./form20240220.php">
<input type="text" name="2024022001"></input>
<input type="submit">
</form>

cs2gqv5bm5r7et0e6h8dh907pb<br>
Super Sache<br>
Hallo Welt<br>
<br>

<?php
session_start ();

include ("/home/david/mysqldata.php");

\$db = new PDO ("mysql: host=localhost", \$MYSQL_USER, \$MYSQL_PASSWORD);

\$sql = "CREATE DATABASE d20240220";
\$db->query (\$sql);

\$sql = "USE d20240220";
\$db->query (\$sql);

\$sql = "CREATE TABLE a (x1 INTEGER, x2 INTEGER); CREATE TABLE b (y1 INTEGER, y2 INTEGER);";
\$db->query (\$sql);

\$sql = "INSERT INTO a (x1, x2) VALUES (0, 0); INSERT INTO a (x1, x2) VALUES (0, 1); INSERT INTO a (x1, x2) VALUES (1, 0); INSERT INTO a (x1, x2) VALUES (1, 1); INSERT INTO a (x1, x2) VALUES (2, 7); INSERT INTO b (y1, y2) VALUES (0, 0); INSERT INTO b (y1, y2) VALUES (1, 1); INSERT INTO b (y1, y2) VALUES (2, 7);";
\$db->query (\$sql);

\$sql = "SELECT x1, x2 FROM a";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", " . \$row [1] . "<br>n";
echo "<br>n";

\$sql = "SELECT y1, y2 FROM b";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", " . \$row [1] . "<br>n";
echo "<br>n";

\$sql = "SELECT x1, x2, y1, y2 FROM a INNER JOIN b";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", " . \$row [1] . ", " . \$row [2] . ", " . \$row [3] . "<br>n";
echo "<br>n";

\$sql = "DROP DATABASE d20240220";
\$db->query (\$sql);

session_destroy ();
?>

0, 0<br>
0, 1<br>
1, 0<br>
1, 1<br>
2, 7<br>
<br>
0, 0<br>
1, 1<br>
2, 7<br>
<br>
0, 0, 0, 0<br>
0, 0, 1, 1<br>
0, 0, 2, 7<br>
0, 1, 0, 0<br>
0, 1, 1, 1<br>
0, 1, 2, 7<br>
1, 0, 0, 0<br>
1, 0, 1, 1<br>
1, 0, 2, 7<br>
1, 1, 0, 0<br>
1, 1, 1, 1<br>
1, 1, 2, 7<br>
2, 7, 0, 0<br>
2, 7, 1, 1<br>
2, 7, 2, 7<br>
<br>

<?php
session_start ();

include ("/home/david/mysqldata.php");

\$db = new PDO ("mysql: host=localhost", \$MYSQL_USER, \$MYSQL_PASSWORD);

\$sql = "DROP DATABASE q20240220";
\$db->query (\$sql);

\$sql = "CREATE DATABASE q20240220";
\$db->query (\$sql);

\$sql = "USE q20240220";
\$db->query (\$sql);

\$sql = "CREATE TABLE a (x INTEGER); CREATE TABLE b (x INTEGER); CREATE TABLE c (x INTEGER);";
\$db->query (\$sql);

for (\$i = 0;  \$i < 24;  \$i++) {
    \$sql = "INSERT INTO a (x) VALUES ("" . rand () % 128 . ""); ";
    \$sql .= "INSERT INTO b (x) VALUES ("" . rand () % 64 . ""); ";
    \$sql .= "INSERT INTO b (x) VALUES ("" . rand () % 32 . ""); ";
    \$db->query (\$sql);
}

\$sql = "SELECT x FROM (SELECT x FROM a UNION SELECT x FROM b) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";
\$sql = "SELECT x FROM (SELECT x FROM a UNION SELECT x FROM c) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM b UNION SELECT x FROM c) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM b) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM c) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM b INTERSECT SELECT x FROM c) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";


\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a UNION SELECT x FROM b) x
                INTERSECT
            SELECT x FROM c
        ) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM c) x
                UNION
            SELECT x FROM (SELECT x FROM b INTERSECT SELECT x FROM c) x
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a UNION SELECT x FROM c) x
                INTERSECT
            SELECT x FROM b
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM b) x
                UNION
            SELECT x FROM (SELECT x FROM c INTERSECT SELECT x FROM b) x
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM b UNION SELECT x FROM c) x
                INTERSECT
            SELECT x FROM a
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM b INTERSECT SELECT x FROM a) x
                UNION
            SELECT x FROM (SELECT x FROM c INTERSECT SELECT x FROM a) x
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt->fetch ())
    echo \$row [0] . ", ";
echo "<br>n";

session_destroy ();
?>

david@laptop-peaq:/var/www/html/mysql20240217/20240220\$ php quantity20240220.php
51, 27, 41, 63, 12, 116, 101, 76, 30, 32, 115, 67, 75, 97, 17, 61, 24, 64, 5, 15, 90, 25, 26, 7, 14, 39, 31, 58, 6, 23, 35, 20, 1, 22, 53, 10, 29, 18, 48, 54, 34, 28, 52, 59, 19, 21, 4, 57, 37, 2, <br>
51, 27, 41, 63, 12, 116, 101, 76, 30, 32, 115, 67, 75, 97, 17, 61, 24, 64, 5, 15, 90, <br>
25, 26, 41, 7, 14, 15, 39, 31, 58, 27, 6, 23, 35, 20, 1, 22, 53, 10, 29, 61, 18, 48, 17, 54, 34, 32, 28, 24, 52, 59, 19, 21, 4, 5, 57, 37, 2, <br>
27, 41, 32, 17, 61, 24, 5, 15, <br>
<br>
<br>
<br>
<br>
27, 41, 32, 17, 61, 24, 5, 15, <br>
27, 41, 32, 17, 61, 24, 5, 15, <br>
41, 15, 27, 61, 17, 32, 24, 5, <br>
41, 15, 27, 61, 17, 32, 24, 5, <br>
david@laptop-peaq:/var/www/html/mysql20240217/20240220\$

Image Screenshot_20240221_145348

 0 0 0 0 0    0
 1 0 0 0 1    0
 2 0 0 1 0    0
 3 0 0 1 1    1
 4 0 1 0 0    1
 5 0 1 0 1    0
 6 0 1 1 0    1
 7 0 1 1 1    1
 8 1 0 0 0    1
 9 1 0 0 1    1
10 1 0 1 0    0
11 1 0 1 1    0
12 1 1 0 0    1
13 1 1 0 1    1
14 1 1 1 0    1
15 1 1 1 1    0


 3 0 0 1 1    1
 4 0 1 0 0    1
 6 0 1 1 0    1
 7 0 1 1 1    1
 8 1 0 0 0    1
 9 1 0 0 1    1
12 1 1 0 0    1
13 1 1 0 1    1
14 1 1 1 0    1


Gruppe 1:
 4 0 1 0 0    1
 8 1 0 0 0    1
Gruppe 2:
 3 0 0 1 1    1
 6 0 1 1 0    1
 9 1 0 0 1    1
12 1 1 0 0    1
Gruppe 3:
 7 0 1 1 1    1
13 1 1 0 1    1
14 1 1 1 0    1

4:6         0 1 - 0
4:12        - 1 0 0
8:9         1 0 0 -
8:12        1 - 0 0
3:7         0 - 1 1
6:7         0 1 1 -
6:14        - 1 1 0
9:13        1 - 0 1
12:13       1 1 0 -
12:!4       1 1 - 0





6:7         0 1 1 -
12:13       1 1 0 -
8:9         1 0 0 -
12:!4       1 1 - 0
4:6         0 1 - 0
8:12        1 - 0 0
3:7         0 - 1 1
9:13        1 - 0 1
6:14        - 1 1 0
4:12        - 1 0 0




Gruppe 2:
6:7         0 1 1 -
12:13       1 1 0 -
Gruppe 1:
8:9         1 0 0 -

Gruppe 2:
12:!4       1 1 - 0
Gruppe 1:
4:6         0 1 - 0

Gruppe 1:
8:12        1 - 0 0
Gruppe 2:
3:7         0 - 1 1
9:13        1 - 0 1

Gruppe 2:
6:14        - 1 1 0
Gruppw 1:
4:12        - 1 0 0




Gruppe 2:
6:7         0 1 1 -
12:13       1 1 0 -
Gruppe 1:
8:9         1 0 0 -

6:8             0 1 1
12:13:8:9       1 - 0 -

Gruppe 2:
12:!4       1 1 - 0
Gruppe 1:
4:6         0 1 - 0

12:14:4:6       - 1 - 0

Gruppe 1:
8:12        1 - 0 0
Gruppe 2:
3:7         0 - 1 1
9:13        1 - 0 1

4:7             0 - 1 1
8:12:9:13       1 - 0 -

Gruppe 2:
6:14        - 1 1 0
Gruppw 1:
4:12        - 1 0 0

6:14:4:!2       - 1 - 0


6:8             0 1 1
12:13:8:9       1 - 0 -
12:14:4:6       - 1 - 0
3:7             0 - 1 1
8:12:9:13       1 - 0 -
6:14:4:!2       - 1 - 0


6:8             0 1 1
3:7             0 - 1 1
12:13:8:9       1 - 0 -
8:12:9:13       1 - 0 -
12:14:4:6       - 1 - 0
6:14:4:!2       - 1 - 0



6:8             0 1 1
3:7             0 - 1 1
12:13:8:9       1 - 0 -
12:14:4:6       - 1 - 0

                3   4   6   7   8   9   12  13  14
6:8                     *       *
3:7             *       *
12:13:8:9                   *   *   *   *
12:14:4:6           *   *               *       *


    y <= (not x3 and x2 and x1) or
            (not x3 and x1 and xo) or
            (x3 and not x1) or
            (x2 and not x0);

    y <= not (
            (x3 or not x2 or not x1) and
            (x3 or not x1 or not x0) and
            (not x3 or x1) and
            (not x2 or x0)
        );

library ieee;
use ieee.std_logic_1164.all;

entity quine20240221 is
port (
    x3, x2, x1, x0: in std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240221 is
begin
    y <= (not x3 and x2 and x1) or
            (not x3 and x1 and x0) or
            (x3 and not x1) or
            (x2 and not x0);
end;

library ieee;
use ieee.std_logic_1164.all;

entity quine20240221testbench is
port (
    y: out std_logic
);
end;

architecture behaviour of quine20240221testbench is
    component quine20240221
    port (
        x3, x2, x1, x0: in std_logic;
        y: out std_logic
    );
    end component;
    signal x3, x2, x1, x0: std_logic;
begin
    q: quine20240221 PORT MAP (x3=>x3, x2=>x2, x1=>x1, x0=>x0, y=>y);

library ieee;
use ieee.std_logic_1164.all;

entity quine20240221 is
port (
    x3, x2, x1, x0: in std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240221 is
begin
    y <= (not x3 and x2 and x1) or
            (not x3 and x1 and x0) or
            (x3 and not x1) or
            (x2 and not x0);
end;

library ieee;
use ieee.std_logic_1164.all;

entity quine20240221testbench is
port (
    y: out std_logic
);
end;

architecture behaviour of quine20240221testbench is
    component quine20240221
    port (
        x3, x2, x1, x0: in std_logic;
        y: out std_logic
    );
    end component;
    signal x3, x2, x1, x0: std_logic;
begin
    q: quine20240221 PORT MAP (x3=>x3, x2=>x2, x1=>x1, x0=>x0, y=>y);

    x0 <= '0' after 0 ns, '1' after 10 ns, '0' after 20 ns, '1' after 30 ns, '0' after 40 ns, '1' after 50 ns, '0' after 60 ns, '1' after 70 ns, '0' after 80 ns, '1' after 90 ns, '0' after 100 ns, '1' after 110 ns, '0' after 120 ns, '1' after 130 ns, '0' after 140 ns, '1' after 150 ns;

    x1 <= '0' after 0 ns, '0' after 10 ns, '1' after 20 ns, '1' after 30 ns, '0' after 40 ns, '0' after 50 ns, '1' after 60 ns, '1' after 70 ns, '0' after 80 ns, '0' after 90 ns, '1' after 100 ns, '1' after 110 ns, '0' after 120 ns, '0' after 130 ns, '1' after 140 ns, '1' after 150 ns;

    x2 <= '0' after 0 ns, '0' after 10 ns, '0' after 20 ns, '0' after 30 ns, '1' after 40 ns, '1' after 50 ns, '1' after 60 ns, '1' after 70 ns, '0' after 80 ns, '0' after 90 ns, '0' after 100 ns, '0' after 110 ns, '1' after 120 ns, '1' after 130 ns, '1' after 140 ns, '1' after 150 ns;

    x3 <= '0' after 0 ns, '0' after 10 ns, '0' after 20 ns, '0' after 30 ns, '0' after 40 ns, '0' after 50 ns, '0' after 60 ns, '0' after 70 ns, '1' after 80 ns, '1' after 90 ns, '1' after 100 ns, '1' after 110 ns, '1' after 120 ns, '1' after 130 ns, '1' after 140 ns, '1' after 150 ns;
end;