会话未定义索引

发布于 2024-11-16 10:08:46 字数 2289 浏览 1 评论 0原文

我正在开发一个聊天框脚本,我有一个页面检查是否设置了会话,如果设置了,则应使用 jQuery 隐藏代码的某些元素。这是我的页面:

input.php:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
    @import "stil.css";
</style>
<title>Untitled Document</title>
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" src="scripts.js"></script>
<script type="text/javascript" src="postme.js"></script>
<?php
include_once('check.php');
?>
</head>
<body>
<div id="wrap">
    <div id="chat">
    <div id="main">
    </div>
    <div id="input">
<form name="form"action="test.php" method="post">
<input type="text" name="tekst" id="msg" size="72" />
<input type="submit" name="dugme" value="posalji" id="dugme" />
</form>
    </div>
    </div>
    </div>
<div id="black">
</div>
<div id="name">
<form name="yname">
<input type="text" name="tekst2" />
<input type="button" name="dugme2" value="Enter" onclick='send()' />    
</form>
</div>


</body>
</html>

session.php:

<?php
session_start();
$_SESSION['ime']=$_POST['ime'];
$sesion_n=$_SESSION['ime'];
echo $sesion_n;
?>

check.php:

<?php
include('sesion.php');
if (!isset($sesion_n)){
    echo "<script type='text/javascript'>$('#black').hide();$('#name').hide();</script>";
}
?>

postme.js:

    function send(){
       $.post('sesion.php',{ime:yname.tekst2.value},function(val){
                if(val!=null) {
                    $('#black').fadeOut();
                    $('#name').hide();
                    alert(val);  
                }

            }

   )};

所以问题是我每次运行页面时都会收到此错误: 注意:未定义索引:ime位于C:\wamp\www\AJAX\sesion.php第3行。
那么有人可以告诉我我在这里做错了什么吗?

I'm developing a chatbox script, and I have this page that checks if session is set, and if so, the certain elements of code should be hidden with jQuery. Here are my pages:

input.php:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
    @import "stil.css";
</style>
<title>Untitled Document</title>
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" src="scripts.js"></script>
<script type="text/javascript" src="postme.js"></script>
<?php
include_once('check.php');
?>
</head>
<body>
<div id="wrap">
    <div id="chat">
    <div id="main">
    </div>
    <div id="input">
<form name="form"action="test.php" method="post">
<input type="text" name="tekst" id="msg" size="72" />
<input type="submit" name="dugme" value="posalji" id="dugme" />
</form>
    </div>
    </div>
    </div>
<div id="black">
</div>
<div id="name">
<form name="yname">
<input type="text" name="tekst2" />
<input type="button" name="dugme2" value="Enter" onclick='send()' />    
</form>
</div>


</body>
</html>

sesion.php:

<?php
session_start();
$_SESSION['ime']=$_POST['ime'];
$sesion_n=$_SESSION['ime'];
echo $sesion_n;
?>

check.php:

<?php
include('sesion.php');
if (!isset($sesion_n)){
    echo "<script type='text/javascript'>$('#black').hide();$('#name').hide();</script>";
}
?>

postme.js:

    function send(){
       $.post('sesion.php',{ime:yname.tekst2.value},function(val){
                if(val!=null) {
                    $('#black').fadeOut();
                    $('#name').hide();
                    alert(val);  
                }

            }

   )};

So the problem is that I get this error every time I run the page:
Notice: Undefined index: ime in C:\wamp\www\AJAX\sesion.php on line 3.
So can someone tell me what I'm doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧街凉风 2024-11-23 10:08:46
if(isset($_POST['ime']))
{
    $_SESSION['ime']=$_POST['ime'];
    $sesion_n=$_SESSION['ime'];
    echo $sesion_n;
}
if(isset($_POST['ime']))
{
    $_SESSION['ime']=$_POST['ime'];
    $sesion_n=$_SESSION['ime'];
    echo $sesion_n;
}
空气里的味道 2024-11-23 10:08:46

似乎 $_POST['ime']; 未定义,这意味着我猜您没有发布它。

您确定 yname.tekst2.value 是访问字段值的正确方法吗?

如果您有萤火虫,您可以在“控制台”选项卡中检查已发布的参数。

it seems that $_POST['ime']; is undefined and that means that you are not posting it i guess.

Are you sure that yname.tekst2.value is the correct way to access the value of the field?

If you have firebug you can check in the "console" tab what parametrs have been posted.

南巷近海 2024-11-23 10:08:46

看来您正在手动加载 check.php 。这将是一个 GET 请求,并且会丢弃您存储的值,因为不会在这些页面上设置 _POST。可能不会是未定义索引问题的原因,但需要考虑。

检查会话的 ID 值在请求之间是否保持不变。如果每次都不同,您将针对每个请求获得一个全新的空白会话。

It appears you're loading check.php manually. That'd be a GET request, and will trash your stored value, as _POST won't be set on those pages. Probably won't be the cause of the undefined index problem, but something to consider.

Check that the session's ID value stays constant between requests. If it's different each time, you're getting a brand new blank session on each request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文