我正在为一个 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 没有改变,但会话 ['logged-in'] 被更改为 0。如果会话 ID 没有改变,那么会话没有重新启动,对吗?