bluedollar
Programmer
I have the following bits of code:
<?php
session_start();
?>
<html>
<head>
<title>Listing 16.2 Storing variables in a session</title>
</head>
<body>
<?php
session_register( "product1" );
session_register( "product2" );
$product1 = "Sonic Screwdriver";
$product2 = "test 2";
print "The products have been registered.";
?>
</body>
</html>
==========================================================
<?php
session_start();
?>
<html>
<head>
<title>Listing 16.3 Accessing stored session variables</title>
</head>
<body>
<?php
print "Your chosen products are:\n\n";
print "<ul><li>$product1\n<li>$product2\n</ul>\n";
?>
</body>
</html>
======================================================
PROBLEM
The first bit of code succefully creates a cookie with the following content:
product1|s:17:"Sonic Screwdriver";product2|s:6:"test 2";
However the second bit of code fails to read this information.
========================================================
CONFIG
The session part of php.ini is configured as follows:
[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 = 1 ; initialize session on request startup
session.cookie_lifetime = 0 ; 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 = ; 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
session.use_trans_sid = 1 ; use transient sid support if enabled
; by compiling with --enable-trans-sid
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
=======================================================
QUESTION
- What am I doing wrong?
Any help would be greatly appreciated.
Thanks
Dan
<?php
session_start();
?>
<html>
<head>
<title>Listing 16.2 Storing variables in a session</title>
</head>
<body>
<?php
session_register( "product1" );
session_register( "product2" );
$product1 = "Sonic Screwdriver";
$product2 = "test 2";
print "The products have been registered.";
?>
</body>
</html>
==========================================================
<?php
session_start();
?>
<html>
<head>
<title>Listing 16.3 Accessing stored session variables</title>
</head>
<body>
<?php
print "Your chosen products are:\n\n";
print "<ul><li>$product1\n<li>$product2\n</ul>\n";
?>
</body>
</html>
======================================================
PROBLEM
The first bit of code succefully creates a cookie with the following content:
product1|s:17:"Sonic Screwdriver";product2|s:6:"test 2";
However the second bit of code fails to read this information.
========================================================
CONFIG
The session part of php.ini is configured as follows:
[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 = 1 ; initialize session on request startup
session.cookie_lifetime = 0 ; 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 = ; 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
session.use_trans_sid = 1 ; use transient sid support if enabled
; by compiling with --enable-trans-sid
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
=======================================================
QUESTION
- What am I doing wrong?
Any help would be greatly appreciated.
Thanks
Dan