Jump to content
Larry Ullman's Book Forums

Session_Start()


Recommended Posts

Hello,

 

I am keep getting this error, can any one help?

 

 

[Warning]: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/datee0/public_html/prgsearch.php:1)

in /home/datee0/public_html//init.php:0

 

Stack Dump:

 

errorHandler(integer(2), string("session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/datee0/public_html/prgsearch.php:1)"), string("/home/datee0/public_html//init.php"), integer(0), array(array))

[/home/datee0/public_html//init.php:0]

 

include(string("/home/datee0/public_html//init.php"))

[/home/datee0/public_html/db_connect.php:96]

 

include(string("/home/datee0/public_html/db_connect.php"))

[/home/datee0/public_html/prgsearch.php:21]

Link to comment
Share on other sites

This is a fairly common problem.

 

It often occurs because you are outputting ANYTHING before the session_start(). It could also be any whitespace above the sesson_start() or any html/includes etc.

 

Make sure session_start() is placed ABOVE all other PHP code and html other than the start tag (<?php) and any type of comments. (// comment, /* comment */)

  • Upvote 1
Link to comment
Share on other sites

Hi Antonio would you be able to tell me what I am doing wrong in my script that generates these errors:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home1/potberry/database/link_db.php:2) in /home1/potberry/public_html/ewe/login.php on line 17

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home1/potberry/database/link_db.php:2) in /home1/potberry/public_html/ewe/login.php on line 17

 

Warning: Cannot modify header information - headers already sent by (output started at /home1/potberry/database/link_db.php:2) in /home1/potberry/public_html/ewe/login_functions.inc.php on line 22

 

 

 

<?php # Script 12.12 - login.php #4

// This page processes the login form submission.

// The script now stores the HTTP_USER_AGENT value for added security.

 

// Check if the form has been submitted:

 

ini_set('display_errors', 1);

 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

// Need two helper files:

require ('login_functions.inc.php');

require ('../../database/link_db.php');

 

// Check the login:

list ($check, $data) = check_login($dbc, $_POST['emailaddress'], $_POST['password']);

 

if ($check) {

session_start();

$_SESSION['customer_id'] = $data['customer_id'];

$_SESSION['firstname'] = $data['firstname'];

 

// Store the HTTP_USER_AGENT:

$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);

 

// Redirect:

redirect_user('loggedin.php');

 

} else { // Unsuccessful!

 

// Assign $data to $errors for login_page.inc.php:

$errors = $data;

 

}

 

mysqli_close($dbc); // Close the database connection.

 

} // End of the main submit conditional.

 

// Create the page:

include ('login_page.inc.php');

 

?>

Link to comment
Share on other sites

Your problem is clearly stated in your error messages:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home1/potberry/database/link_db.php:2) in /home1/potberry/public_html/ewe/login.php on line 17

 

That means that link_db.php is outputting something on line 2.

 

By the way, the book does assume complete comfort with PHP and MySQL.

Link to comment
Share on other sites

 Share

×
×
  • Create New...