Jump to content
Larry Ullman's Book Forums

Recommended Posts

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');
?>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.
 

Share this post


Link to post
Share on other sites

Thanks for the nice words. I really appreciate it. As for your issue, what is the full and complete error message you're seeing?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...