dmx1 Posted February 5, 2022 Share Posted February 5, 2022 Hi Larry, I put the website online on a hosting server with a few html design alterations. It works fine up until when I try and get onto the checkout.php page. It gives me the following error: 'checkout.php' on line 10: session_id(): Cannot change session id when headers already sent' I removed all the ?> tags from the all .php files. I have spent two whole days trying to find out what the problem is, but nothing. The problem occurs when I get to the line session_id($uid); on the 'checkout.php' page on page 297. If I remove the lines: session_id($uid); session_start(); in the checkout.php on page 297, I then get access to the 'checkout.php' page. For some reason, the session_id($uid); and session_start() lines are the problematic lines. Can you suggest what it could be, and what I could do to fix the problem. Thank you regards Link to comment Share on other sites More sharing options...
dmx1 Posted February 6, 2022 Author Share Posted February 6, 2022 (edited) Note: For some reason, the lines are getting spaced out Hi Larry, I made a slight adjustment in the checkout.php file. I simply moved the session_id($uid) and session_start() lines to the top of the page, and it works. I can now go straight to the checkout.php page without it giving me the error 'session_id(): Cannot change session id when headers already sent' For example on the checkout.php page I commented out the session_id($uid) and session_start() lines, and just put them right at the start of the checkout.php page on page 297 as follows: <?php session_id($uid); session_start(); require('./includes/config.inc.php'); // Check for the user's session ID, to retrieve the cart contents: if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($_COOKIE['SESSION']) && (strlen($_COOKIE['SESSION']) === 32)) { $uid = $_COOKIE['SESSION']; // Use the existing user ID: //session_id($uid); // Start the session: //session_start(); } else { // Redirect the user. $location = 'http://' . BASE_URL . 'cart.php'; header("Location: $location"); exit(); } } else { // POST request. session_start(); $uid = session_id(); } Qu 1: Can I leave it like this, or won't this work? Qu 2: Based on what I just did, what do you think could be the problem? It seems the problem starts after the require('./includes/config.inc.php') line. If I could just simply put the code at the top of the page, this would solve the problem, but I don't know if this is allowed. Also, I would like to find out why the original code in the checkout.php page stops working and throws out the error message: session_id(): Cannot change session id when headers already sent' regards Edited February 6, 2022 by dmx1 Lines are too spaced out Link to comment Share on other sites More sharing options...
dmx1 Posted February 7, 2022 Author Share Posted February 7, 2022 Hi Larry, I sorted the problem. Please ignore the previous posts. Thank you! Link to comment Share on other sites More sharing options...
Larry Posted February 8, 2022 Share Posted February 8, 2022 Kudos for solving it! Link to comment Share on other sites More sharing options...
Recommended Posts