, and [quote] tags when appropriate.[/COLOR][/B]
Hi,
First time using sessions.
I created a Userlogin functionality to the website I am creating.
I had the index.php page where it takes the username and password and checks against a file where I have the password and when it is correct assigns the username to a variable called "logged".
[php]
$_SESSION["logged"]=$_POST["username"];[/php]
Now, in all the pages I have, i have included the following code segment,
[php]
<?php
session_start(); /// initialize session
include("passwords.php");
check_logged(); /// function checks if visitor is logged. If user is not logged the user is redirected to login.php page
?>[/php]
where the passwords.php is
[php]
<?
$USERS["user1"] = "pass1";
$USERS["user2"] = "pass2";
$USERS["user3"] = "pass1";
function check_logged(){
global $_SESSION, $USERS;
if (!array_key_exists($_SESSION["logged"],$USERS)) {
header("Location: index.php");
};
};
?>[/php]
Question:
In those pages I already had two includes so I uncluded the code segment after that.
Like this:
[php]
<?php
include("top.php");
include("conn.php");
session_start(); /// initialize session
include("passwords.php");
check_logged(); /// function checks if visitor is logged. If user is not logged the user is redirected to login.php page
?>
When I did that, I got the following error message.
[quote]
"session_start(): Cannot send session cache limiter - headers already sent[/quote] (output started at top.htm............"
I took the code segment out from all the pages and put on top of top.php, it works fine.
Why does that session_start() should be on top the file. Or is it some other problem caused this error ?
Thanks for your time
Shiyam
[B]John | [COLOR="Red"]Please use [code=auto:0], [php], and [quote] tags when appropriate.
Edited by John, 03 September 2008 - 07:38 PM.