PHP在jquery选项卡页面提交表单后开始会话


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);
                }       
            });
});

我还检查用户是否登录了,是否有会话。

在提交i之后,执行以下函数来(重新)启动会话:

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。在/home/huurhulp/domain/huurhulp.nl/public_html/wijzigen/basisgegevens_verhuur.php中,第23行

警告:session_regenerate_id() [function.]/home/huurhulp/domain/huurhulp.nl/public_html/inloggen/login_functions.php第24行已经发送的session-regenerate-id]:无法重新生成session id - headers

我如何摆脱错误,是否有必要重新启动功能,或者我可以使用已经在主页上启动的功能(标签在哪里)

在调用session_start()session_regenerate_id()函数之前,您几乎肯定会发送某种形式的输出。这样做的问题是,要发送输出,必须先发送HTTP头…但是会话是由cookie管理的,它必须在报头中发送。然后发生的是,你发送你的头,发送一些页面内容,然后尝试发送更多的头。那不行。

确保在开始或更改会话之前不输出任何页面内容。

更多信息:如何修复"头已经发送"PHP出错