Mark Mark - 4 months ago 13
PHP Question

php undefined index in

<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css"/>
<title>
Metin2 Bash-Panel by .Infinity - ChatBlock-Panel
</title>
</head>
<body>
<center>
<img src="../images/head.jpg"/>
</center>
<div id="main">
<center>
<i>
<b>
<a href="../index.php"> Panel-Auswahl </a>
<a href="index.php"> Startseite </a>
<a href="shutdown_p2p.php"> Server herunterfahren </a>
<a href="notice_p2p.php"> Ank√ľndigungen schreiben </a>
<a href="block_chat_p2p.php"> ChatBlock-Panel </a>
<a href="dc_p2p.php"> DC-Panel </a>
<a href="rc_p2p.php"> RufChat-Panel </a>
</b>
</i>
<div id="php">

<?php
/* block_chat_p2p.php by .Infinity

*/

// Variablensetzung

$IP = $_POST['ip'];
$LogData_IP = $_SERVER['REMOTE_ADDR'];
$Port = $_POST['port'];
$Submit = $_POST['submit'];
$Player = $_POST['player'];
$Time = $_POST['time'];

if($Submit)
{
if(strlen($IP) < 1)
{
echo "<br /><br /><b>Bitte gebe eine IP an!</b><br />";
}

if(strlen($Port) < 1)
{
echo "<br /><br /><b>Bitte gebe einen Port an!</b><br />";
}

if(empty($Player))
{
echo "<br /><br /><b>Bitte geben sie einen Spielernamen ein!</b><br />";
}

}

if($IP && $Port && $Player)
{
$LogData = fopen("../log/log_data_block_chat_p2p.txt", "a");
fwrite($LogData, "$IP:$Port from $LogData_IP");
fwrite($LogData, "\n");
fclose($LogData);
$socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect ($socket, $IP, $Port);

$msg = $Player;
$time = "100";
$msgsize = strlen($msg);
$maximumsize = "25";

$query = "\x16".$msg;

$leftsize = $maximumsize - $msgsize;

while($leftsize)
{
$query = $query."\x00";
$leftsize = $leftsize - 1;
}

$query = $query.$time."\x00";

$query_size = strlen($query);
$write_res = socket_write($socket, $query, $query_size);
$recv_res = socket_recv($socket, $output, 5056, 0);
echo "<br />";
echo "<br />";
echo "<b>Der Spieler ".$Player." hat einen Chatblock erhalten.</b>";
socket_close($socket);
}
?>

</div>
<form method="POST">
<div id="input">
<b>
<br />
<br />
Bitte geben sie eine ServerIP ein!
<br />
<br />
<input type="text" name="ip"/>
<br />
<br />
Bitte geben sie einen P2PPort ein!
<br />
<br />
<input type="text" name="port"/>
<br />
<br />
Bitte geben sie einen SpielerNamen ein!
<br />
<br />
<input type="text" name="player"/>
<br />
<br />
<br />
</div>
<input class="submit" type="submit" name="submit" value="ChatBlock setzen!"/>
<br />
<br />
</b>
</form>
</center>
</div>
</body>
</html>


Can someone tell me what is wrong with this little code? I just started to learn php and html.. I get this error
Notice: Undefined index: ip in C:\xampp\htdocs\p2p\block_chat_p2p.php on line 34

Notice: Undefined index: port in C:\xampp\htdocs\p2p\block_chat_p2p.php on line 36

Notice: Undefined index: submit in C:\xampp\htdocs\p2p\block_chat_p2p.php on line 37

Notice: Undefined index: player in C:\xampp\htdocs\p2p\block_chat_p2p.php on line 38

Notice: Undefined index: time in C:\xampp\htdocs\p2p\block_chat_p2p.php on line 39

Answer

Try it:

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="../style.css"/>
        <title>
            Metin2 Bash-Panel by .Infinity - ChatBlock-Panel
        </title>
    </head>
    <body>
    <center>
        <img src="../images/head.jpg"/>
    </center>
    <div id="main">
        <center>
            <i>
                <b>
                    <a href="../index.php"> Panel-Auswahl </a>
                    <a href="index.php"> Startseite </a>
                    <a href="shutdown_p2p.php"> Server herunterfahren </a>
                    <a href="notice_p2p.php"> Ank√ľndigungen schreiben </a>
                    <a href="block_chat_p2p.php"> ChatBlock-Panel </a>
                    <a href="dc_p2p.php"> DC-Panel </a>
                    <a href="rc_p2p.php"> RufChat-Panel </a>
                </b>
            </i>
            <div id="php">

                <?php
                /* block_chat_p2p.php by .Infinity

                 */

// Variablensetzung
                if (isset($_POST['submit'])) {
                    $IP = isset($_POST['ip']) ? $_POST['ip'] : "";
                    $LogData_IP = $_SERVER['REMOTE_ADDR'];
                    $Port = isset($_POST['port']) ? $_POST['port'] : "";

                    $Player = isset($_POST['player']) ? $_POST['player'] : "";
                    $Time = isset($_POST['time']) ? $_POST['time'] : "";


                    if (strlen($IP) < 1) {
                        echo "<br /><br /><b>Bitte gebe eine IP an!</b><br />";
                    }

                    if (strlen($Port) < 1) {
                        echo "<br /><br /><b>Bitte gebe einen Port an!</b><br />";
                    }

                    if (empty($Player)) {
                        echo "<br /><br /><b>Bitte geben sie einen Spielernamen ein!</b><br />";
                    }

                    if ($IP && $Port && $Player) {
                        $LogData = fopen("../log/log_data_block_chat_p2p.txt", "a");
                        fwrite($LogData, "$IP:$Port from $LogData_IP");
                        fwrite($LogData, "\n");
                        fclose($LogData);
                        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
                        $result = socket_connect($socket, $IP, $Port);

                        $msg = $Player;
                        $time = "100";
                        $msgsize = strlen($msg);
                        $maximumsize = "25";

                        $query = "\x16" . $msg;

                        $leftsize = $maximumsize - $msgsize;

                        while ($leftsize) {
                            $query = $query . "\x00";
                            $leftsize = $leftsize - 1;
                        }

                        $query = $query . $time . "\x00";

                        $query_size = strlen($query);
                        $write_res = socket_write($socket, $query, $query_size);
                        $recv_res = socket_recv($socket, $output, 5056, 0);
                        echo "<br />";
                        echo "<br />";
                        echo "<b>Der Spieler " . $Player . " hat einen Chatblock erhalten.</b>";
                        socket_close($socket);
                    }
                }
                ?>

            </div>
            <form method="POST">
                <div id="input">
                    <b>
                        <br />
                        <br />
                        Bitte geben sie eine ServerIP ein!
                        <br />
                        <br />
                        <input type="text" name="ip"/>
                        <br />
                        <br />
                        Bitte geben sie einen P2PPort ein!
                        <br />
                        <br />
                        <input type="text" name="port"/>
                        <br />
                        <br />
                        Bitte geben sie einen SpielerNamen ein!
                        <br />
                        <br />
                        <input type="text" name="player"/>
                        <br />
                        <br />
                        <br />
                </div>
                <input class="submit" type="submit" name="submit" value="ChatBlock setzen!"/>
                <br />
                <br />
                </b>
            </form>
        </center>
    </div>
</body>
</html>