[SOLVED] Warning: session_start(): Cannot send session cooki

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

microshaft
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 3:11 pm

[SOLVED] Warning: session_start(): Cannot send session cooki

Post by microshaft »

HI,

I have looked at all the forums and i seem to be doing all they ask but i still get the following message

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\inetpub\wwwroot\rivaaz\index.php:1) in c:\inetpub\wwwroot\rivaaz\index.php on line 1

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\rivaaz\index.php:1) in c:\inetpub\wwwroot\rivaaz\index.php on line 1

the follwing is php code which contains all the session stuff. also i have a inlude language file
---------- index.php---------------------------------------------------

Code: Select all

<?session_start();

if (!isset($_REQUEST['lang']))
{
$def_lang="en";
session_register("user_lang");
$HTTP_SESSION_VARS['user_lang']=$def_lang;
}
else
{
$HTTP_SESSION_VARS['user_lang']=$_REQUEST['lang'];

}
include("inc/langs/lang.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>RIVAAZ</title>
-------------include language file lang.php--------------------------------

Code: Select all

<?

if ($_SESSION['user_lang']=="en")
{
$home="HOME";
$collection="COLLECTION";
$about="ABOUT";
$contact="CONTACT";
}
?>
most of the forums suggest having the start_session at the top . Ive tired changing it around but no luck.

im using php4.3 os win xp with iis 4

i hope some one can guide me where im going wrong
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

output buffering. quick fix - ob_start but this is a bad way to do it
microshaft
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 3:11 pm

Post by microshaft »

im sorry im kinda new to all this where do i place the ob_start() function
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Do you see something missing? :)

Code: Select all

<?session_start();
i think

Code: Select all

<?php session_start();
is better line to replace your first.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

first line put ob_start();
microshaft
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 3:11 pm

Post by microshaft »

dethron wrote:Do you see something missing? :)

Code: Select all

<?session_start();
i think

Code: Select all

<?php session_start();
is better line to replace your first.

tried that same error message

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\inetpub\wwwroot\rivaaz\index.php:1) in c:\inetpub\wwwroot\rivaaz\index.php on line 1

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\rivaaz\index.php:1) in c:\inetpub\wwwroot\rivaaz\index.php on line 1
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

and if you still have problem after replacing as i suggested, may be the reason you are using Macromedia Dreamweaver MX as your text ediyor. ;)
microshaft
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 3:11 pm

Post by microshaft »

shiznatix wrote:first line put ob_start();

tried that too

Code: Select all

<?php ob_start(); 
session_start();

if (!isset($_REQUEST['lang']))
{
$def_lang="en";
session_register("user_lang");
$HTTP_SESSION_VARS['user_lang']=$def_lang;
}
else
{
$HTTP_SESSION_VARS['user_lang']=$_REQUEST['lang'];

}
include("inc/langs/lang.php");
?>
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\inetpub\wwwroot\rivaaz\index.php:1) in c:\inetpub\wwwroot\rivaaz\index.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\rivaaz\index.php:1) in c:\inetpub\wwwroot\rivaaz\index.php on line 2

Sorry same error message
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

are you using Macromedia Dreamweaver MX?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

<?
ob_start(); 
session_start();
 
if (!isset($_POST['lang']))//or $_GET['lang']
{
$def_lang="en";
$_SESSION['user_lang'] = $def_lang;
}
else
{
//use get OR post instead of request
$_SESSION['user_lang'] = $_POST['lang'];//or get $_GET['lang'];
 
}
include("inc/langs/lang.php");
?>
try that
microshaft
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 3:11 pm

Post by microshaft »

dethron wrote:and if you still have problem after replacing as i suggested, may be the reason you are using Macromedia Dreamweaver MX as your text ediyor. ;)

i used dreamweaver initially, but i have been coding the php using Ultraedit.
but how would dreamweaver screw it up
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

since first you have created the file using Dreamweaver, the file has some special characters that prvent session to start.

you can use vi editor to see them in linux, or homesite in windows.

if you dont have one of them, let me know, and i will tell you what to do...
microshaft
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 3:11 pm

Post by microshaft »

dethron wrote:since first you have created the file using Dreamweaver, the file has some special characters that prvent session to start.

you can use vi editor to see them in linux, or homesite in windows.

if you dont have one of them, let me know, and i will tell you what to do...
sorry dont have any of those
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

since you dont have vi editor, and most *nix common installations have this editor, i assume you are using windows.

go to command line (cmd OR command) and run edit (classical windows editor).

at the beginning you will see some nasty characters ;)

good luck...
microshaft
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 3:11 pm

Post by microshaft »

dethron wrote:since you dont have vi editor, and most *nix common installations have this editor, i assume you are using windows.

go to command line (cmd OR command) and run edit (classical windows editor).

at the beginning you will see some nasty characters ;)

good luck...

YOUR A STAR D thanks alot it worked. i hated frontpage but i think im gona add dreamweaver to my list

Thanks again
Post Reply