会话正在特定页面上重新启动

时间:2012-06-03 08:23:26

标签: php jquery session

我正在为uni项目开发一个基于php的站点。

一切正常,我正在使用会话来存储登录用户的数据。

我有一个页面,使用jquery,用户可以标记图像。 jquery使用php来保存带有标签的txt文件。在那个php页面中我添加了“session_start();”在顶部,以便我也可以在mysql数据库中存储一些信息。

但是我发现当我标记图像时,实际发生的是会话正在重新启动,因此用户正在注销,并且没有任何内容存储在数据库中。

任何想法我可能做错了什么? (它正在我的项目的所有其他页面上工作,只有这个javascript + php组合似乎导致了问题)。

这是来自php页面的代码,它由javascript调用。它来自第三方jquery插件,我已经添加了自己的代码:

session_start();

    include 'notes.class.php';
    require_once '../db.php';

    if (isset($_POST['image']) && !empty($_POST['image']))
    $oNote = new note('../jquery-notes_notes/', '', (string) strip_tags($_POST['image']), '.note');
        $NoteName = md5(strip_tags($_POST['image']));
        $NoteName .= '.note';
        $ImageID = $_SESSION['CurrentImage'];

        //get the name of the last poster if the user is logged in, its the username, otherwise its the comment name
        if ($_SESSION['logged_in'] == 1) {
            $LastNoteBy = $_SESSION['username'];
        } else {
            $LastNoteBy = 'Guest: '.$_SESSION['commentname'];
        }

        //get relevant info for this image
        $DBQueryImageData = mysqli_query($dblink, "SELECT * FROM images WHERE image_id = '$ImageID'");
        while($row = mysqli_fetch_array($DBQueryImageData)) {
            $DBImageUserID = $row['user_id'];
            $DBImageName = $row['image_name'];
            $DBGivenName = $row['given_name'];
            $DBImageLasteNoteBy = $row['last_note_by'];
            $DBImageProjectID = $row['project_id'];
        }

        //get the project name of the related project
        $DBQueryProjectName = mysqli_query($dblink, "SELECT * FROM projects WHERE project_id = '$DBImageProjectID'");
        while($row = mysqli_fetch_array($DBQueryProjectName)) {
            $DBProjectName = $row['project_name'];
        }

        //get the username of the owner of the previously obtained user_id
        $DBQueryUsername = mysqli_query($dblink, "SELECT * FROM users WHERE user_id = '$DBImageUserID'");
        while($row = mysqli_fetch_array($DBQueryUsername)) {
            $DBUsername = $row['username'];
            $DBEmail = $row['email'];
            $DBNotify = $row['notify'];
        }

        //only send off the email if the user has asked to receive notifications
        if ($DBNotify == 1) {

            //compare the current poster to the last poster saved for this image, if they are different, and if the current poster is not the owner, email the owner of the project
            //if the last poster is not the same as the current poster
            if ($DBImageLasteNoteBy != $LastNoteBy) {

                //if the current poster is not the owner
                if ($LastNoteBy != $DBUsername) {

                    if (strlen($DBGivenName) > 4) {
                        $DBImageName = $DBGivenName;
                    }

                    //send the email
                    $to = $DBEmail;
                    $subject = "New comment on your project image";
                    $headers = 'From: test@test.com' . "\r\n" .
                    'Reply-To: test@test.com' . "\r\n" .
                    'X-Mailer: PHP/' . phpversion();
                    $additionalParameters = '-ODeliveryMode=d'; 
                    $body = 'Hi '.$DBUsername.','."\n\n".'A comment has been made by '.$LastNoteBy.' on your image: '.$DBImageName.' in your project: '.$DBProjectName."\n\n".
                    'http://'.$_SERVER['SERVER_NAME'].'/saeproj/index.php?page=project&id='.$DBImageProjectID;

                    mail($to, $subject, $body, $headers, $additionalParameters);

                }
            }
        }

        mysqli_query($dblink, "UPDATE images SET note = '$NoteName', last_note_by = '$LastNoteBy' WHERE image_id = '$ImageID'") or die(mysql_error());

更新:我刚注意到我没有登录在我的iMac上运行的MAMP版本。但我正在登录我的托管网站空间(ipower是主机)。

更新2:我刚检查过,会话ID没有改变,但会话['登录']正在更改为0.如果会话ID没有改变,那么会话没有重启,对吗?

1 个答案:

答案 0 :(得分:2)

事实证明,在托管网站空间上,register_globals设置为“On”。关闭它解决了问题。