Reputation: 259
i am beginner in php i search for hours and try everthing that i can but still getting this error. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/apsterne/public_html/mag/main.php:1) in /home/apsterne/public_html/mag/includes/functions.php on line 3
this is my login page where i'm logging in and going for main page
include_once('includes/functions.php');
include_once('includes/connection.php');
if(loggedin())
{
header("location:main.php");
exit();
}
if (isset($_POST['submit'])){
$error=array();
if($_POST['username']=="") $error[]='Please Enter Username';
if($_POST['password']=="") $error[]='Please Enter Password';
if(isset($_GET['e'])) $error[]='You Are Trying to access secure page without login';
if(isset($_POST['rememberme'])) $remember=$_POST['rememberme'];
function cleanStr($str) {
$cStr = trim($str);
$cStr = htmlspecialchars($cStr);
$cStr = addslashes($cStr);
return $cStr;
}
$userName = cleanStr($_POST['username']);
$pwd = cleanStr($_POST['password']);
$result=mysql_query("SELECT * FROM login WHERE username = '$_POST[username]'");
$row=mysql_fetch_array($result);
if(empty($error)){
if($userName==$row['username'] && $pwd==$row['password'] ){
if($rememberme=="on")
setcookie("username",$userName,time()+7200);
else if($rememberme==""){
$_SESSION['username']=$userName;
header("location:main.php");
exit();
}
}
else
$error[]='You Enter Wrong username and password';
}
}
THis is main page
<?php
include_once('includes/functions.php');
include_once('includes/connection.php');
if(!loggedin())
{
header("location:index.php");
exit();
}
?>
And This is Function File
<?php
session_start();
function loggedin()
{
if(isset($_SESSION['username']) || isset ($_COOKIE['username']))
{
$loggedin=TRUE;
return TRUE ;
}
}
?>
There is no whitespace and i dont know what is this..
Upvotes: 1
Views: 278
Reputation: 3319
Double-check main.php. The engine is claiming that the very first line has output, possibly before the <?php
tag. (Accidental BOM (byte-order mark for old UTF-8 files) character?)
Upvotes: 1
Reputation: 9329
I think you have a blank line in one or more of your files or you saved some of them with UTF-8 encoding + bite order mark bytes. Try to save them with UTF-8 without BOM.
Upvotes: 1
Reputation: 57693
This happens if you send any content (being non headers) before calling session_start
.
Is there maybe trailing or leading whitespace? Did you encode your files at utf-8 with BOM?
For this reason it's generally recommended to omit the final ?>
php closing tag.
Upvotes: 1