получение уведомления: неопределенный индекс: текст в строке 4

4:$textik = $_POST['text'];

и я получаю

примечание: неопределенный индекс: текст в пути / к / скрипту в строке 4.

Зачем?

URL:
http://somesite.domain/path/to/script?text=something
Спасибо за ответы

изменить: полный скрипт в пути / к / скрипту

 <?php
session_start();
if(isset($_SESSION['name'])){
    $textik = $_POST['text'];
    date_default_timezone_set(date_default_timezone_get());
    $time = date('h:i', time()); 
    $fp = fopen("log.html", 'a');
    fwrite($fp, "<li class='other'>
      <div class='msg'>
          <div class='user'>".$_SESSION['name']."</div>
        <p>".stripslashes(htmlspecialchars($textik))."</p>
        <time>".$time."</time>
      </div>
    </li>");
    fclose($fp);
}
?> 

а в пути / к / другой скрипт -

<?php
session_start ();
function loginForm() {
    echo '
    <div id="loginform">
    <form action="index.php" method="post">
        <p>Please enter your name to continue:</p>
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" />
        <input type="submit" name="enter" id="enter" value="Enter" />
    </form>
    </div>
    ';
}

if (isset ( $_POST ['enter'] )) {
    if ($_POST ['name'] != "") {
        $_SESSION ['name'] = stripslashes ( htmlspecialchars ( $_POST ['name'] ) );
        $fp = fopen ( "log.html", 'a' );
        date_default_timezone_set(date_default_timezone_get());
    $time = date('h:i', time());
        fwrite ( $fp, "<p class='notification'> ". $_SESSION ['name'] . " left the group <time>". $time."</time></p>" );
        fclose ( $fp );
    } else {
        echo '<span class="error">Please type in a name</span>';
    }
}

if (isset ( $_GET ['logout'] )) {

    // Simple exit message
    $fp = fopen ( "log.html", 'a' );
    fwrite ( $fp, "<div class='msgln'><i>User " . $_SESSION ['name'] . " has left the chat session.</i><br></div>" );
    fclose ( $fp );

    session_destroy ();
    header ( "Location: index.php" ); // Redirect the user
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel='stylesheet' type='text/css' href='new.css'>
<title>AZsites chat</title>
</head>
<body>
    <?php
    if (! isset ( $_SESSION ['name'] )) {
        loginForm ();
    } else {
        ?>
<div id="wrapper">
    <ol class="chat">
        <div class="menu">
            <a href="#" class="back"><i class="fa fa-angle-left"></i> <img src="https://i.imgur.com/G4EjwqQ.jpg" draggable="false"/></a>
            <div class="name">AZsites chat</div>
    <div class="members"><b><?php echo $_SESSION['name']; ?></b> a dalsi</div>
        </div><?php
        if (file_exists ( "log.html" ) && filesize ( "log.html" ) > 0) {
            $handle = fopen ( "log.html", "r" );
            $contents = fread ( $handle, filesize ( "log.html" ) );
            fclose ( $handle );

            echo $contents;
        }
        ?></ol></div>
    <div class="typezone">
<form name="message" action='' method='post'><textarea name="text" id="usermsg" size="63"type="text" placeholder="Napis neco"></textarea><input type="submit" class="send" value="odeslat"/></form>
<div class="emojis"></div></div>
    </div>
    <script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script type="text/javascript">
// jQuery Document
$(document).ready(function(){
});

//jQuery Document
$(document).ready(function(){
    //If user wants to end session
    $("#exit").click(function(){
        var exit = confirm("Are you sure you want to end the session?");
        if(exit==true){window.location = 'index.php?logout=true';}      
    });
});

//If user submits the form
$("#submitmsg").click(function(){
        var clientmsg = $("#usermsg").val();
        $.post("post.php", {text: clientmsg});              
        $("#usermsg").attr("value", "");
        loadLog;
    return false;
});

function loadLog(){     
    var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request
    $.ajax({
        url: "log.html",
        cache: false,
        success: function(html){        
            $("#chatbox").html(html); //Insert chat log into the #chatbox div   

            //Auto-scroll           
            var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height after the request
            if(newscrollHeight > oldscrollHeight){
                $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
            }               
        },
    });
}

setInterval (loadLog, 500);
</script>
<?php
    }
    ?>
    <script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script type="text/javascript">
</script>
</body>
</html>

поэтому мне нужно иметь сообщение, потому что он работает в фоновом режиме, обычный пользователь его не видит, но здесь есть редактирование, чтобы увидеть его, но я не знаю, как отредактировать его до нормального состояния ..... Пожалуйста, помогите мне ... спасибо!


person Dan B.    schedule 02.08.2017    source источник
comment
должно быть ПОЛУЧЕНИЕ   -  person Masivuye Cokile    schedule 02.08.2017


Ответы (2)


Вы используете $_POST вместо $_GET. Ваш URL-адрес http://somesite.domain/path/to/script?text=something и text - параметр GET.

Итак, вам нужно изменить

$textik = $_POST['text'];

to

$textik = $_GET['text'];
person Variable    schedule 02.08.2017
comment
Верно, но я отредактировал его, и он работает, но он больше похож на предыдущий, у него есть POST, а не GET. Но спасибо, теперь я знаю, как это сделать. - person Dan B.; 03.08.2017

Вам нужно использовать GET, а не POST

$textik = $_GET['text'];

Прочтите эту статью W3Schools для большей ясности.

person Scott    schedule 02.08.2017