4:$textik = $_POST['text'];
即将到来
注意:未定义的索引:第4行的路径/到/脚本中的文字。
为什么?
网址是
http://somesite.domain/path/to/script?text=something
谢谢你的回答
编辑: path / to / script中的完整脚本是
<?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);
}
?>
并且在path / to / anotherscript中
<?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>
所以我需要发帖,因为它在后台运行,普通用户不会看到它,但是这里有一个编辑看到它,但我不知道如何将其编辑为正常状态..... 请帮我... 谢谢!
答案 0 :(得分:0)
答案 1 :(得分:0)
您使用$_POST
代替$_GET
。您的网址为http://somesite.domain/path/to/script?text=something,text
是GET参数。
所以你需要改变
$textik = $_POST['text'];
到
$textik = $_GET['text'];