0

I use a page with Jquery tabs and when i submit one of the tabs it only submits that tab, zo the other tabs stay the same (and do not submit). I use:

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

Also i check if the user is logged in, with a session.

After a submit i execute the following function to (re) start a session:

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. 
}

After that i do the login chech:

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

Problem is that the following error occurs:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/huurhulp/domains/huurhulp.nl/public_html/wijzigen/basisgegevens_verhuur.php:5) in /home/huurhulp/domains/huurhulp.nl/public_html/inloggen/login_functions.php on line 23

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /home/huurhulp/domains/huurhulp.nl/public_html/inloggen/login_functions.php on line 24

How do i gett rid of the error, Is i necessery to restart the function or can i use the function that is already starter on the main page (where the tabs are on).

Jilco Tigchelaar
  • 2,065
  • 8
  • 31
  • 51

1 Answers1

1

You are almost certainly sending some form of output before you are calling the session_start() and session_regenerate_id() functions. The problem with this is that, for output to be sent, the HTTP headers must be sent first... But sessions are managed by cookies, which must be sent in the headers. What's happening, then, is that you're sending your headers, sending some page content, and then trying to send more headers. That won't work.

Make sure you don't output any page content before starting or changing the session.

More info: How to fix "Headers already sent" error in PHP

Community
  • 1
  • 1
John Chrysostom
  • 3,973
  • 1
  • 34
  • 50