我正在爲uni項目開發一個基於php的網站。會話在特定頁面上重新啓動
一切工作,我使用一個會話存儲記錄在誰的用戶數據。
我有一個頁面,使用jQuery的,用戶可以標記的圖像。 jquery使用php來保存一個帶有標籤的txt文件。在那個php頁面中,我添加了「session_start();」在頂部,這樣我也可以在mysql數據庫中存儲一些信息。
但我發現,當我標記圖像時,實際發生的是會話正在重新啓動,因此用戶正在註銷,並且沒有任何內容存儲在數據庫中。
任何想法我可能做錯了什麼? (它在我的項目的所有其他頁面上工作,只有這個JavaScript + 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: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\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版本。但是我正在登出我的託管webspace(ipower是主機)。
更新2:我剛剛檢查並且會話ID沒有改變,但會話['logged-in']正在改爲0.如果會話ID沒有改變,那麼會話沒有重新啓動,是否正確?
你的問題很難回答。通常是的,它沒有重啓,但另一方面,你確實需要調試。但是這需要在你身邊完成,所以我在這裏幫不了什麼忙。 – hakre
也許有和沒有www的問題。但是用你的描述來猜測是不可能的。 :-( – Oliver
有趣的是,我剛剛意識到register_globals在託管帳戶上設置爲「on」,將其關閉以解決問題。 – PartisanEntity