Page 1 of 1

session does not works!!

PostPosted: 26. August 2006 10:48
by mehrzadsoft
hi all
i'm a new xampp user.
after instalation i did not changed any of its options or anything else.

i used this code below, but i can't use PHP SESSION.

could you please help me.

CODE:

page1.php
Code: Select all
<?php
session_start();

echo 'Welcome to page #1';

$_SESSION['favcolor'] = 'green';
$_SESSION['animal']  = 'cat';
$_SESSION['time']    = time();

// Works if session cookie was accepted
echo '<br /><a href="page2.php">page 2</a>';

// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
?>



Page2.php

Code: Select all
<?php
session_start();
echo("Hi, $animal -- <br>Credit: $favcolor $time");
?>



i see this error:

Code: Select all
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\win--64--1--9tir85\unzipped\xampp\htdocs\www\test\session\page1.php:1) in F:\win--64--1--9tir85\unzipped\xampp\htdocs\www\test\session\page1.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\win--64--1--9tir85\unzipped\xampp\htdocs\www\test\session\page1.php:1) in F:\win--64--1--9tir85\unzipped\xampp\htdocs\www\test\session\page1.php on line 2
Welcome to page #1
page 2
page 2

PostPosted: 26. August 2006 11:06
by Wiedmann
Code: Select all
<?php
session_start();

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\win--64--1--9tir85\unzipped\xampp\htdocs\www\test\session\page1.php:1)... on line 2

There must be some output before "<?php".

BTW:
You set the session vars with:
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();

and want retrieve them with:
echo("Hi, $animal -- <br>Credit: $favcolor $time");

You see the difference?
--> You must allways use the $_SESSION array.

tanx

PostPosted: 27. August 2006 22:08
by mehrzadsoft
i've found it!

i use NOTEPAD and this programm adds some hidden codes at the beggining of the php file, so i had problem.

thanks for your hint about mu mistake in PAGE2.

thanks all 8)

PostPosted: 12. January 2007 08:41
by hoergen
That has nothing to do with buggy code. There is a unhappy configuration in php.ini

Change the session.save_path to something like

Code: Select all
session.save_path = "0;600;C:\Temp


dem hoergen