[英]php start session after submit of form in jquery tabs page
我使用帶有Jquery選項卡的頁面,當我提交其中一個選項卡時,它僅提交該選項卡,而其他選項卡則保持不變(並且不提交)。 我用:
$(document).on("submit","#basis_advertentie,#prijzen_huidige_jaar", function(event) {
$.ajax({
type:"POST",
url:this.getAttribute('id')+".php",
cache: false,
data: data,
success:function(data){
wijziging_nog_bevestigen = 0;
$(innertab).html(data);
}
});
});
我也檢查用戶是否登錄了會話。
提交后,我執行以下功能來(重新)開始會話:
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = TRUE; //origineel was SECURE
// This stops JavaScript being able to access the session id.
$httponly = true;
// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
//header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
email_error("Could not initiate a safe session (ini_set)): ");
exit();
}
// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly);
// Sets the session name to the one set above.
session_name($session_name);
session_start(); // Start the PHP session
session_regenerate_id(); // regenerated the session, delete the old one.
}
之后,我執行登錄檢查:
function login_check($mysqli) {
// Check if all session variables are set
if (isset($_SESSION['user_id'],
$_SESSION['username'],
$_SESSION['login_string'])) {
$user_id = $_SESSION['user_id'];
$login_string = $_SESSION['login_string'];
$username = $_SESSION['username'];
// Get the user-agent string of the user.
$user_browser = $_SERVER['HTTP_USER_AGENT'];
if ($stmt = $mysqli->prepare("SELECT wachtwoord
FROM data_adverteerders
WHERE adverteerder_ID = ? LIMIT 1")) {
// Bind "$user_id" to parameter.
$stmt->bind_param('i', $user_id);
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
if ($stmt->num_rows == 1) {
// If the user exists get variables from result.
$stmt->bind_result($wachtwoord);
$stmt->fetch();
$login_check = hash('sha512', $wachtwoord . $user_browser);
if ($login_check == $login_string) {
// Logged In!!!!
return true;
} else {
// Not logged in
return false;
}
} else {
// Not logged in
return false;
}
} else {
// Not logged in
return false;
}
} else {
// Not logged in
return false;
}
}
問題是發生以下錯誤:
警告:session_start()[function.session-start]:無法發送會話緩存限制器-已發送標頭(輸出從/home/huurhulp/domains/huurhulp.nl/public_html/wijzigen/basisgegevens_verhuur.php:5開始) /huurhulp/domains/huurhulp.nl/public_html/inloggen/login_functions.php,第23行
警告:session_regenerate_id()[function.session-regenerate-id]:無法重新生成會話ID-在第24行的/home/huurhulp/domains/huurhulp.nl/public_html/inloggen/login_functions.php中已發送的標頭
我如何擺脫錯誤,我是否需要重新啟動該功能,或者我可以使用主頁上已經啟動的功能(選項卡處於打開狀態)。
幾乎可以肯定,在調用session_start()
和session_regenerate_id()
函數之前,您已經發送了某種形式的輸出。 問題在於,要發送輸出,必須首先發送HTTP標頭...但是,會話由cookie管理,必須在標頭中發送。 然后,發生的事情是您要發送標題,發送一些頁面內容,然后嘗試發送更多標題。 那行不通。
在開始或更改會話之前,請確保不輸出任何頁面內容。
更多信息: 如何修復PHP中的“標題已發送”錯誤
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.