Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-03-2008, 10:28 PM
shiyam198 shiyam198 is offline
Newbie
 
Join Date: Sep 2008
Posts: 11
Rep Power: 0
shiyam198 is on a distinguished road
Default Question on Sessions

John | Please use [code], [php], and [quote] tags when appropriate.
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 Code:
$_SESSION["logged"]=$_POST["username"]; 
Now, in all the pages I have, i have included the following code segment,
PHP Code:
<?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
?>
where the passwords.php is
PHP Code:
<?
$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");
     };
};
?>
Question:

In those pages I already had two includes so I uncluded the code segment after that.

Like this:
PHP Code:
<?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
(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
John | Please use [code], [php], and [quote] tags when appropriate.

Last edited by John; 09-03-2008 at 11:38 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-03-2008, 11:36 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Re: Question on Sessions

Quote:
Originally Posted by shiyam198 View Post
When I did that, I got the following error message.
(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 ?
The cache limiter warning is issued when content is outputted prior to the session_start() directive being called. That said, it must be placed at the top of the page (or before you output any content). I'm not sure the reasoning behind it - I just accepted it.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbe C# Platform question cob98tp C# Programming 28 07-30-2008 09:01 AM
Question about IT jobs in USA. Red19 The Lounge 9 06-01-2008 11:13 AM
Question about C# user int input TheMagicalRock C# Programming 3 04-01-2008 09:36 AM
Question johnny The Lounge 3 03-17-2008 08:08 AM


All times are GMT -5. The time now is 07:12 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads