会话变量在使用Chrome和IE而不是Firefox进行测试时有效

时间:2010-08-17 18:24:21

标签: php session-variables

我正在使用PHP和一些Javascript编写测验程序。使用IE或Chrome时可以正确回答问题但Firefox会刷新页面并增加会话变量。

以下是代码段:

 if(isset($_GET['answer1']))
{
    if($_GET['answer'] == $_GET['answer1'])
    {
        include 'config.php';
        if (!$con) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db, $con);
    $userId = $_SESSION['userId'];
    $wordNow = $_SESSION['word'];
    $sql3 = "SELECT * FROM userAccomplishments Where UserId = '$userId' AND 
    word = '$wordNow'";

    $result3 = mysql_query($sql3);
    if (mysql_num_rows($result3) == 0) {
    $sql4 = "SELECT wordId from allwords WHERE word = '$wordNow'";
    $result = mysql_query($sql4);
    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting from random number";
        exit;
    }
    while ($row = mysql_fetch_assoc($result)) {
        $wordId = $row["wordId"];
        //       echo $row["word"] . " " ."<BR>" ;
    }
    list($usec, $sec) = explode(' ', microtime());
    $script_end = (float) $sec + (float) $usec;
    $elapsed_time = (float)($script_end - $script_start);
    $elapsed_time = $_GET['formvar'];
    $sql2 = "INSERT INTO userAccomplishments (UserId, word, TimeTaken, wordId)
        VALUES ('$userId',   '$wordNow', '$elapsed_time', '$wordId')";
    echo 'You got '. $wordNow . ' in  ' .$elapsed_time . ' seconds. <BR><BR>';
    $result = mysql_query($sql2);
    }         
     $_SESSION['views'] = $_SESSION['views'] + 1;
    }
    else
    {
         $_SESSION['views'] = $_SESSION['views'] + 1;
        echo 'Keep studying <BR>';
    }


}
else
{
    $_SESSION['views'] = 1;

}

1 个答案:

答案 0 :(得分:1)

看起来你没有打电话给session_start()。确保你打电话让你的会议开始!呜!呀!