Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/02/8573202/html/fakehome.php:4) in /home/content/02/8573202/html/Core.php on line 3
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/02/8573202/html/fakehome.php:4) in /home/content/02/8573202/html/Core.php on line 3
I did everything I know to do (delete white spaces and make sure it is UTF8 without BOM), but am still getting the errors. This is my first time really working at a somewhat higher level with PHP and I would love some help. As far as output goes, I know that there can't be any before the session_start() code, but does that include all pages in my website? My other pages such as index.php and fakehome.php have output, but since they are completely different files from the Core.php (page where I use session() start), I don't know whether or not that would matter. Here is the code, and thanks so much for anyone who could give me some insight.
Code: Select all
//Core.php
<?php
ob_start();
session_start();
$current_file = $_SERVER['SCRIPT_NAME'];
$http_referer = $_SERVER['HTTP_REFERER'];
function loggedin() {
if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
return true;
} else {
return false;
}
}
function getUserField($field) {
$query = "SELECT `$field` FROM `users` WHERE `id`='".$_SESSION['user_id']."'";
if($query_run = mysql_query($query)) {
if ($query_result = mysql_result($query_run, 0, $field)) {
return $query_result;
}
}
}
?>Code: Select all
//fakehome.php -- page that includes Core and is where I am getting the error.
<html><head>
</head>
<body style="" >
<?php
require 'Connect.php';
require 'Core.php';
if(loggedin()) {
$firstname = getUserField('firstname');
$surname = getUserField('surname');
echo 'You have successfully logged in, '.$firstname.' '.$surname.'. <a href="LogOut.php">Log Out</a><br>';
} else {
include 'LogInForm.php';
}
?>
//some html code
</body></html>