1

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..

1
  • i simply copy all the contents to new file and then it works for me Thanks to all stackoverflow members... it was BOM Commented Mar 15, 2012 at 3:32

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

how can i save file without BOM
On Windows platform try notepad++ on any other try simething similar editor but for example Netbans saves the files without BOM.
Thanks i open a new file in notepadd++ and copy all the code to that and save that.. and it works for me... Thanks
1

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.

1 Comment

Ye i encoded this file in utf-8 what do u mean by omitting the final ?> tag
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.