php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13841 new session ID with each session_start()
Submitted: 2001-10-26 17:43 UTC Modified: 2001-10-29 16:55 UTC
From: thomas at neweve dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.0.6 OS: Red Hat 6.1
Private report: No CVE-ID: None
 [2001-10-26 17:43 UTC] thomas at neweve dot com
I am making a desperate cry. I seem to be the only one on 
the face of the planet who has this problem. Whenever I 
post to the PHP-general group the discussion goes on and 
then ends up with someone writing me saying, "gee man, I 
don't know".

I put in a bug report about this back at php 4.0.1pl2 and 
it was concluded that I was using the POST value instead of 
GET in the form. That bug is this: 
http://bugs.php.net/bug.php?id=5360

Now, in PHP 4.0.6 it still plagues me and there's a program 
I need to run on my server and it won't run because of my 
session problem.

Okay, so this is the deal in a nutshell.  With each 
subsequent call to 'session_start()' instead of picking up 
the existing session, it creates a new PHPID.  This happens 
whether I have the sessionID in a cookie or passed via a 
variable (VIA THE QUERYSTRING).  I have included code for 
two files that I use as a demonstration so you can check 
the code, and I can send you to a website where you can see 
it in action..

Code:

filename: index.php
----------
<?
error_reporting(E_ALL);
session_start();

$var1 = "My var 1";
$var2 = "My var 2";

session_register("var1");
session_register("var2");

?><HTML>
<HEAD>
<TITLE>Session Page 1</TITLE>
</HEAD>

<BODY BGCOLOR=#FFFFFF>

PHPSESSID: <? echo session_id(); ?><BR>
Var1: <? echo $var1; ?><BR>
Var2: <? echo $var2; ?><BR>

<FORM ACTION="index2.php" METHOD="POST">
Passing sessid: <INPUT TYPE=TEXT VALUE="<? echo 
session_id(); ?>" SIZE=40 NAME="PHPSESSID"><BR>
VAR 3: <INPUT TYPE=TEXT VALUE="My Var 3" NAME="myvar3"> 
<INPUT TYPE=SUBMIT VALUE="go"><BR>
</FORM>
<BR>
<A HREF="index2.php?<?=SID?>">Try this link</A>
</BODY>
</HTML>
----------

filename: index2.php
----------
<?
error_reporting(E_ALL);
session_start();                // start session
session_register("var3");      // register var 3 session 
variable

$var3 = $myvar3;
?><HTML>
<HEAD>
<TITLE>Session Page 2</TITLE>
</HEAD>

<BODY BGCOLOR=#FFFFFF>

PHPSESSID: <? echo session_id(); ?><BR>
Var1: <? echo $var1; ?><BR>
Var2: <? echo $var2; ?><BR>
VAR3: <? echo $var3; ?><BR>

</BODY>
</HTML>
----------

in action: http://www.fromtheduke.com/session/index.php

I have noticed with other pages that I have tried this on 
this same server that the session_start() will create a new 
session ID three times, on the third one, it 'sticks' and 
stays with me the rest of the time.

here is my php.ini file which shows my session variable 
options:
------------
[Session]
session.save_handler      = files   ; handler used to 
store/retrieve data
session.save_path         = /tmp    ; argument passed to 
save_handler
                                    ; in the case of files, 
this is the
                                    ; path where data files 
are stored
session.use_cookies       = 1       ; whether to use 
cookies
session.name              = PHPSESSID
                                    ; name of the session
                                    ; is used as cookie 
name
session.auto_start        = 0       ; initialize session on 
request startup
session.cookie_lifetime   = 0    ; lifetime in seconds of 
cookie
                                    ; or if 0, until 
browser is restarted
session.use_trans_sid     = 1
session.cookie_path       = /       ; the path the cookie 
is valid for
session.cookie_domain     =         ; the domain the cookie 
is valid for
session.serialize_handler = php     ; handler used to 
serialize data
                                    ; php is the standard 
serializer of PHP
session.gc_probability    = 1       ; percentual 
probability that the
                                    ; 'garbage collection' 
process is started
                                    ; on every session 
initialization
session.gc_maxlifetime    = 1440    ; after this number of 
seconds, stored
                                    ; data will be seen as 
'garbage' and
                                    ; cleaned up by the gc 
process
session.referer_check     = 0        ; check HTTP Referer 
to invalidate
                                    ; externally stored 
URLs containing ids
session.entropy_length    = 0       ; how many bytes to 
read from the file
session.entropy_file      =         ; specified here to 
create the session id
; session.entropy_length    = 16
; session.entropy_file      = /dev/urandom
session.cache_limiter     = nocache ; set to 
{nocache,private,public} to
                                    ; determine HTTP 
caching aspects
session.cache_expire      = 180     ; document expires 
after n minutes
------------

I am at my wit's end. I NEED HELP. Please please help me oh 
PHP programming gods. I have no where else to turn.

This problem happens with Macintosh and Windows Browsers, 
Netscape or internet Explorer, it doesn't matter.

My server info: http://stjohn.neweve.com/phpinfo.phtml

I'm happy to give help to anyone that will work with me.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-29 11:09 UTC] thomas at neweve dot com
I have two servers setup exactly the same (for the most 
part.)

I don't know much about linux and this other company put it 
together but both installations have the same version of 
Red Hat on it and I use the same exact commands to install 
apache/PHP on both servers.

This second server processes and works with Sessions 
perfectly fine. NO hitches. The problem is that the server 
is password protected so I cannot give access to my 
tests.I'll see if I can get a non-protected virtual server 
on there for you to see.

It's got to be a server installation thing, I think. What 
could be some issues with an OS installation which could 
cause this problem?
 [2001-10-29 15:51 UTC] thomas at neweve dot com
YOU CAN MARK AS SOLVED OR BOGUS (or use this as some way to 
improve the system?)

My sessions are fixed. I compaired the two php.ini files 
from the server that works and the server that didn't work.  
Here's the two.  notice the one difference (trans-id).

Working server:
[Session]
session.save_handler      = files   ; handler used to 
store/retrieve data
session.save_path         = /tmp    ; argument passed to 
save_handler
                                    ; in the case of files, 
this is the
                                    ; path where data files 
are stored
session.use_cookies       = 1       ; whether to use 
cookies
session.name              = PHPSESSID  
                                    ; name of the session
                                    ; is used as cookie 
name
session.auto_start        = 0       ; initialize session on 
request startup
session.cookie_lifetime   = 3600    ; lifetime in seconds 
of cookie
                                    ; or if 0, until 
browser is restarted
session.cookie_path       = /       ; the path the cookie 
is valid for
session.cookie_domain     =         ; the domain the cookie 
is valid for
session.serialize_handler = php     ; handler used to 
serialize data
                                    ; php is the standard 
serializer of PHP
session.gc_probability    = 1       ; percentual 
probability that the 
                                    ; 'garbage collection' 
process is started
                                    ; on every session 
initialization
session.gc_maxlifetime    = 1440    ; after this number of 
seconds, stored
                                    ; data will be seen as 
'garbage' and
                                    ; cleaned up by the gc 
process
session.referer_check     =         ; check HTTP Referer to 
invalidate 
                                    ; externally stored 
URLs containing ids
session.entropy_length    = 0       ; how many bytes to 
read from the file
session.entropy_file      =         ; specified here to 
create the session id
; session.entropy_length    = 16
; session.entropy_file      = /dev/urandom
session.cache_limiter     = nocache ; set to 
{nocache,private,public} to
                                    ; determine HTTP 
caching aspects
session.cache_expire      = 180     ; document expires 
after n minutes
--------------------
Non-working Server:
[Session]
session.save_handler      = files   ; handler used to 
store/retrieve data
session.save_path         = /tmp    ; argument passed to 
save_handler
                                    ; in the case of files, 
this is the
                                    ; path where data files 
are stored
session.use_cookies       = 1       ; whether to use 
cookies
session.name              = PHPSESSID  
                                    ; name of the session
                                    ; is used as cookie 
name
session.auto_start        = 0       ; initialize session on 
request startup
session.cookie_lifetime   = 0    ; lifetime in seconds of 
cookie
                                    ; or if 0, until 
browser is restarted
session.use_trans_sid     = 1
session.cookie_path       = /       ; the path the cookie 
is valid for
session.cookie_domain     =         ; the domain the cookie 
is valid for
session.serialize_handler = php     ; handler used to 
serialize data
                                    ; php is the standard 
serializer of PHP
session.gc_probability    = 1       ; percentual 
probability that the 
                                    ; 'garbage collection' 
process is started
                                    ; on every session 
initialization
session.gc_maxlifetime    = 1440    ; after this number of 
seconds, stored
                                    ; data will be seen as 
'garbage' and
                                    ; cleaned up by the gc 
process
session.referer_check     = 0        ; check HTTP Referer 
to invalidate 
                                    ; externally stored 
URLs containing ids
session.entropy_length    = 0       ; how many bytes to 
read from the file
session.entropy_file      =         ; specified here to 
create the session id
; session.entropy_length    = 16
; session.entropy_file      = /dev/urandom
session.cache_limiter     = nocache ; set to 
{nocache,private,public} to
                                    ; determine HTTP 
caching aspects
session.cache_expire      = 180     ; document expires 
after n minutes
------------------

I copied over the config and now it's working fine.
 [2001-10-29 16:55 UTC] sniper@php.net
I can't see the difference, but if it works, fine.

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 17:01:31 2024 UTC