会话未在下一页保留原始值

时间:2014-11-17 18:55:11

标签: php session

此页面显示了几个聊天室的状态。用户可以单击按钮将他们带入他们选择的人的房间。他们选择的人的昵称会话应通过表格发送到会议室。会话在此页面上是正确的,但是当值提交到会议室时,昵称将更改为数据库中的第一个昵称,而不是我传递给页面的昵称。如何让会话使用最初收集的数据? (仅接收值的页面是echos会话,所以我没有发布它)

<?php
session_start();
require_once('connect.php');


$con = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME) or die('Connection failed: ' . mysqli_connect_error());

$sql = mysqli_query($con, "SELECT UserType, NickName, Online, InChat FROM main_member WHERE UserType = 2 ORDER BY Online DESC");


    while($row = mysqli_fetch_array($sql)){

        $UserType = $row['UserType'];
        $NickName = $row['NickName'];
        $Online = $row['Online'];
        $InChat = $row['InChat'];

    $_SESSION['NickName_Session'] = $NickName;

        echo '<table width="353" border="0">';
        echo '<tbody>';
        echo '<tr>';
        echo '<td width="248" height="51">';
        echo Status($Online,$InChat,$NickName); 
        echo '</td>';
        echo '</tr>';
        echo '</tbody>';
        echo '</table>';

     }

function Status($Online,$InChat,$NickName){ 

    if ($Online == 0) {
        echo 'I am not online.';
    }

    elseif($Online == 1 && $InChat == 0){
        echo 'I am online and I will be in my chatroom shortly.';
    }

    elseif($Online == 1 && $InChat == 1){
        echo 'I am online.';
        echo '<form name="get_nickname" id="get_nickname" action="script.php" method="POST">';
        echo '<input type="hidden" name="nickname" id="nickname" value="' . $_SESSION['NickName_Session'] . '">';
        echo '<input type="submit" name="submit" id="submit" value="Start Chat" />';
        echo '</form>';

    }
}

mysqli_close($con);
?> 

这是脚本页面:

session_start();


if(!isset($_SESSION['file'])) {
    $_SESSION['file'] = (rand(1000000, 9999999)) . round(10*microtime(TRUE));
}

if(isset($_POST['create'])) {
    $_SESSION['file'] =  (rand(1000000, 9999999)) . round(10*microtime(TRUE));
}
$url='chat_container.php';
Header("Location: $url");
exit();

这是我需要昵称的聊天容器:

session_start();
require_once('connect.php');

echo   $_SESSION['NickName_Session'];

0 个答案:

没有答案