I am getting the following warnings and am wondering how to clean my code up so it wont do this.
The warnings are>
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/omgma/public_html/Fresh_start/includes/header_fns.php5:17) in /home/omgma/public_html/Fresh_start/member.php5 on line 5
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/omgma/public_html/Fresh_start/includes/header_fns.php5:17) in /home/omgma/public_html/Fresh_start/member.php5 on line 5
running function check_valid_user()
The code that is doing this is coming from the following file when I submit a form with blank username and blank password:
<?php
// include function files for this application
require_once('includes/member_fns.php5');
session_start();
//create short variable names
$username = (isset($_POST['username'])) ? $_POST['username'] : NULL;
$passwd = (isset($_POST['passwd'])) ? $_POST['passwd'] : NULL;
if ($username && $passwd)
// they have just tried logging in
{
try
{
login($username, $passwd);
// if they are in the database register the user id
$_SESSION['valid_user'] = $username;
}
catch(Exception $e)
{
// unsuccessful login
do_html_header('Problem:');
echo '<p>Unsuccessful login at line 22:member.php5</p>';
echo '<P><B>You could not be logged in. </B></P>
<P>You must be logged in to view this page.</P>';
do_html_url('login.php5', 'Login');
do_html_footer();
exit;
}
}
do_html_header('Line 32 members.php5'); //it seems to drop to here!!
check_valid_user();
// get the bookmarks this user has saved
if ($url_array = get_user_urls($_SESSION['valid_user']))
display_user_urls($url_array);
// give menu of options
display_user_menu();
do_html_footer();
?>
The valid_user function is in another file as follows:
<?php
require_once("db_fns.php5");
function check_valid_user()
// see if somebody is logged in and notify them if not
{
if ($_SESSION[valid_user])
{
print("Logged in as $_SESSION[valid_user]<br>");
}
else
{
// they are not logged in
print("<h2>You are not logged in. Please try again! </h2>");
exit;
}
}
?>
Is this the wrong way to use Sessions or what do I do to fix it?