By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

session_start failure

P: n/a
Hello,

I've searched about my problem on google before posting, but I didn't find
anything relevant...

I have a problem with session_start. Here is my code :

<html>
<head>
<?php session_start();
$id = session_id();
$_SESSION['color'] = 'green'; ?>
<title>PHP test</title>
</head>
<body>
this is my ID : <?php echo $id; ?>
<br />
these are my data : <?php print_r($_SESSION); ?>
</body>
</html>

the value printed by "echo $id" or "echo session_id()" is empty!
As I use post or get to transmit the session id, my scripts don't work.

The reason may be in the log. Here are the messages I get when I try to
execute the code above :

[Tue Mar 30 18:12:02 2004] [error] PHP Warning: session_start(): The
session id contains invalid characters, valid characters are only a-z, A-Z
and 0-9 in /home/www/session.php on line 3
[Tue Mar 30 18:12:02 2004] [error] PHP Warning: Unknown(): The session id
contains invalid characters, valid characters are only a-z, A-Z and 0-9 in
Unknown on line 0
[Tue Mar 30 18:12:02 2004] [error] PHP Warning: Unknown(): Failed to write
session data (files). Please verify that the current setting of
session.save_path is correct (/tmp) in Unknown on line 0

How can the session id contain invalid characters, as it is PHP who decides
it!

I read many times the doc, I do not understand where I'm wrong...

Thanks for any tip.

--
Florence HENRY
florence point henry arobasse obspm point fr
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Florence --

session_start() sends a cookie to the browser. A cookie is sent via the
headers, which have to be sent to the browser BEFORE anything else (such as
HTML) is sent. Attempting to set a cookie after you have already output HTML
(the HTML you had output was "<html>" and "<head>") will result in an error.
You have to move the session_start() command to the very beginnning of your
PHP page. So your code should be changed to look like this:

<?php session_start();
$id = session_id();
$_SESSION['color'] = 'green'; ?>
<html>
<head>
<title>PHP test</title>
</head>
<body>
this is my ID : <?php echo $id; ?>
<br />
these are my data : <?php print_r($_SESSION); ?>
</body>
</html>

"Florence HENRY" <ra******@duspam.fr> wrote in message
news:c4**********@carbone.net.espci.fr...
Hello,

I've searched about my problem on google before posting, but I didn't find
anything relevant...

I have a problem with session_start. Here is my code :

<html>
<head>
<?php session_start();
$id = session_id();
$_SESSION['color'] = 'green'; ?>
<title>PHP test</title>
</head>
<body>
this is my ID : <?php echo $id; ?>
<br />
these are my data : <?php print_r($_SESSION); ?>
</body>
</html>

the value printed by "echo $id" or "echo session_id()" is empty!
As I use post or get to transmit the session id, my scripts don't work.

The reason may be in the log. Here are the messages I get when I try to
execute the code above :

[Tue Mar 30 18:12:02 2004] [error] PHP Warning: session_start(): The
session id contains invalid characters, valid characters are only a-z, A-Z
and 0-9 in /home/www/session.php on line 3
[Tue Mar 30 18:12:02 2004] [error] PHP Warning: Unknown(): The session id
contains invalid characters, valid characters are only a-z, A-Z and 0-9 in
Unknown on line 0
[Tue Mar 30 18:12:02 2004] [error] PHP Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of
session.save_path is correct (/tmp) in Unknown on line 0

How can the session id contain invalid characters, as it is PHP who decides it!

I read many times the doc, I do not understand where I'm wrong...

Thanks for any tip.

--
Florence HENRY
florence point henry arobasse obspm point fr

Jul 17 '05 #2

P: n/a
According to Vulcan logic - or learning thereof - kingofkolt wrote:
Florence --

session_start() sends a cookie to the browser. A cookie is sent via the
headers, which have to be sent to the browser BEFORE anything else (such
as HTML) is sent. Attempting to set a cookie after you have already output
HTML (the HTML you had output was "<html>" and "<head>") will result in an
error. You have to move the session_start() command to the very beginnning
of your PHP page. So your code should be changed to look like this:

<?php session_start();
$id = session_id();
$_SESSION['color'] = 'green'; ?>
<html>
<head>
<title>PHP test</title>
</head>
<body>
this is my ID : <?php echo $id; ?>
<br />
these are my data : <?php print_r($_SESSION); ?>
</body>
</html>

"Florence HENRY" <ra******@duspam.fr> wrote in message
news:c4**********@carbone.net.espci.fr...
Hello,

I've searched about my problem on google before posting, but I didn't
find anything relevant...

I have a problem with session_start. Here is my code :

<html>
<head>
<?php session_start();
$id = session_id();
$_SESSION['color'] = 'green'; ?>
<title>PHP test</title>
</head>
<body>
this is my ID : <?php echo $id; ?>
<br />
these are my data : <?php print_r($_SESSION); ?>
</body>
</html>

the value printed by "echo $id" or "echo session_id()" is empty!
As I use post or get to transmit the session id, my scripts don't work.

The reason may be in the log. Here are the messages I get when I try to
execute the code above :

[Tue Mar 30 18:12:02 2004] [error] PHP Warning: session_start(): The
session id contains invalid characters, valid characters are only a-z,
A-Z and 0-9 in /home/www/session.php on line 3
[Tue Mar 30 18:12:02 2004] [error] PHP Warning: Unknown(): The session
[id
contains invalid characters, valid characters are only a-z, A-Z and 0-9
in Unknown on line 0
[Tue Mar 30 18:12:02 2004] [error] PHP Warning: Unknown(): Failed to

write
session data (files). Please verify that the current setting of
session.save_path is correct (/tmp) in Unknown on line 0

How can the session id contain invalid characters, as it is PHP who

decides
it!

I read many times the doc, I do not understand where I'm wrong...

Thanks for any tip.

--
Florence HENRY
florence point henry arobasse obspm point fr


Damn, I should have seen that. I was looking at it, but didn't see the
obvious.

/Andreas
--
Peace and long life ...
Registeret Linux user #292411
Jul 17 '05 #3

P: n/a
kingofkolt a écrit :
session_start() sends a cookie to the browser. A cookie is sent via the
headers, which have to be sent to the browser BEFORE anything else (such
as HTML) is sent. Attempting to set a cookie after you have already output
HTML (the HTML you had output was "<html>" and "<head>") will result in an
error. You have to move the session_start() command to the very beginnning
of your PHP page. So your code should be changed to look like this:


Thanks for your explanation. It works nice now!

Obviously, I did not understand what the manual said... I did not undersand
that cookies was the default method used, then I did not take care of the
sentence saying "If you are using cookie-based sessions, you must call
session_start() before anything is outputted to the browser."
--
Florence HENRY
florence point henry arobasse obspm point fr
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.