|
Posted by Toby A Inkster on 08/20/07 09:12
amygdala wrote:
> As a side note, also keep in mind that nothing should be outputted to the
> users browser before you call session_start(). Not even whitespace
> characters. This is often overlooked by people that have difficulty getting
> sessions to work.
Actually, you *can* output stuff before calling session_start() *except
when*:
1. You are using cookie-based sessions; *and*
2. The user's session cookie hasn't been set yet.
e.g.
<?php
# This is http://example.org/page1.php
session_start();
$_SESSION['foo'] = 'bar';
header("Location: http://example.org/page2.php");
?>
<?php
# This is http://example.org/page2.php
echo "I am going to the ";
session_start(); # Note: after output!
$_SESSION['quux'] = 'quuux';
echo $_SESSION['foo'];
echo ".\n";
?>
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 60 days, 12:44.]
TrivialEncoder/0.2
http://tobyinkster.co.uk/blog/2007/08/19/trivial-encoder/
Navigation:
[Reply to this message]
|