surfmad74 Posted December 13, 2011 Share Posted December 13, 2011 I'm working through Larry's PhP 6 and MySqL 5 book which so far has been excellent but I've hit a snag I can't get past. On Chapter 11 'Cookies & Sessions' I've completed page 327 - 339 and when I test my pages on my MacOSX running Xampp I get errors shown below. Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/php/mysqli_connect.php:4) in /Applications/XAMPP/xamppfiles/htdocs/php/ch11/login.php on line 23 Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/php/mysqli_connect.php:4) in /Applications/XAMPP/xamppfiles/htdocs/php/ch11/login.php on line 24 Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/php/mysqli_connect.php:4) in /Applications/XAMPP/xamppfiles/htdocs/php/ch11/login.php on line 28 I've checked the code and removed all the spaces after the final ?> php tag but I still get the error. Could you help please, many thanks in advance. Below is the code on 'Login.php' Line 23/24 is the setcookie function Line 28 is the header function <?php # Script 9.3 - login.php // This page processes the login form submission. // Upon successful login, the user is redirected. // Two included files are necessary. // Send NOTHING to the Web browser prior to the setcookie() lines! // Check if the form has been submitted: if (isset($_POST['submitted'])) { // For processing the login: require_once ('includes/login_functions.inc.php'); // Need the database connection: require_once ('../mysqli_connect.php'); // Check the login: list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']); if ($check) { // OK! // Set the cookies: setcookie ('user_id', $data['user_id']); setcookie ('first_name', $data['first_name']); // Redirect: $url = absolute_url ('loggedin.php'); header("Location:$url"); exit(); // Quit the script. } else { // Unsuccessful! // Assign $data to $errors for error reporting // in the login_page.inc.php file. $errors = $data; } mysqli_close($dbc); // Close the database connection. } // End of the main submit conditional. // Create the page: include ('includes/login_page.inc.php'); ?> Link to comment Share on other sites More sharing options...
rob Posted December 13, 2011 Share Posted December 13, 2011 Clue is in the error message: output started at /Applications/XAMPP/xamppfiles/htdocs/php/mysqli_connect.php:4 Check your mysqli_connect.php script for whitespace: make sure there's no whitespace before the opening <?php and remove the closing ?> if the file doesn't contain any html. Link to comment Share on other sites More sharing options...
surfmad74 Posted December 13, 2011 Author Share Posted December 13, 2011 Hi I fixed the problem and your right. It wasn't a space as such causing the problem, I included a comment on mysqli_connect.php before the opening <?php tag as soon as I removed it the page worked. thanks for your help! Link to comment Share on other sites More sharing options...
bikesuper Posted May 16, 2015 Share Posted May 16, 2015 This books is very well thought-out. Love the book. There's this challenge for me: I, too, can not figure out why this does not work. I'm on hmm. 3 hours ish 4 hours ish? On this. :'( I tried searching for white space and have not been successful. function redirect_user ($page = 'loggedin.php') { $url = 'http://' . $_SERVER['localhost'] . dirname($_SERVER['htdocs']); $url = rtrim($url, '/\\'); $url .= '/' . $page; // Redirect the user: header("Location: $url"); exit(); // Quit the script. } Link to comment Share on other sites More sharing options...
Larry Posted May 16, 2015 Share Posted May 16, 2015 Thanks for the nice words. I really appreciate it. As for your issue, what is the full and complete error message you're seeing? Link to comment Share on other sites More sharing options...
Recommended Posts