473,326 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

session_start failure

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
3 2879
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Chris Allen | last post by:
Hi I'm new to PHP and I'm trying to create a Login Form. Once the user has logged in then he shouldn't have to log in again. The trouble is I'm getting a new session ID between every page and so...
2
by: Reply-Via-Newsgroup Thanks | last post by:
Folks, I consider myself a reasonably strong PHP programmer, but I've not used sessions before (I've used cookies instead) and I'd appreciate it if someone could confirm something for me. ...
4
by: Bob | last post by:
Seem to have a problem ending a session. I get the following message. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at...
5
by: Ben | last post by:
Hi all, In my .php file, I'm using both session_start() and setcookie() before <html> tag. It gives me following warning message: Warning: Cannot modify header information - headers already...
3
by: Trogdor | last post by:
I set up a server on an AMD 650 machine running gentoo linux. I installed Apachie 2, MySQL 4.1 and PHP 4.3.11 I use another computer on my local net (192.168.0.x) to access the server as a...
1
by: Mercy | last post by:
Hi, I'm a newbie. I was trying to figure out how to use the Session_start method? The reference books I'm reading say that a session STARTS when "session_start" is called. But ... in their sample...
8
by: lkrubner | last post by:
I was trying to set a cookie before I called session_start() and it was giving me an error. But isn't sessions really just a cookie? Why would it matter if I sent a cookie before session_start? Can...
5
by: Niklas Uhlin | last post by:
Someone please explain why Session_Start fires multiple times / retains SessionID values between sessions, when you open an ASP.NET page from MS Word. For details of the problem, see below: 1....
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.