session problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

Which settings do you mean?
global_variables=on
and I have specified a session save path for apache.
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

here is the session part on my php.ini:


[Session]
session.save_handler = files ; handler used to store/retrieve data
session.save_path = c:\Temp ; 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.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
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"
maldar
Forum Commoner
Posts: 49
Joined: Mon Aug 18, 2003 4:39 pm

Post by maldar »

for security reason it can be off (from php 4.2 it is default setting): register_globals=Off
note that $_SESSION is a global variables

ofcourse Note that you are using php 4.0.5 and $_SESSION Introduced in 4.1.0. In earlier versions,you must use $HTTP_SESSION_VARS.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

maldar wrote:you must use session_start() at the beginnig of every page you want use session variables.

try this $_SESSION[test] NOT $_SESSION['test']
Just a note. The above is not entirely correct. It depends on if and where the other quotes reside. If your error_level is bumbed to max, you'll get errors trying to echo $_SESSION[test] without quotes.

Code: Select all

$_SESSION['test'] = 1;
echo $_SESSION['test'];
mysql_query("select * from table where id = $_SESSION[test]");
maldar
Forum Commoner
Posts: 49
Joined: Mon Aug 18, 2003 4:39 pm

Post by maldar »

Thanks to Jam and his good note :wink:
digihoo
Forum Newbie
Posts: 4
Joined: Wed Oct 01, 2003 12:53 pm

Post by digihoo »

yaron,

have a look at your "phpinfo.php" page and make sure that Session Support is enabled.
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

Yaron,

What operating system and web server are you using?

Under Windows 2000+ you must give the anonymous user id the proper security level to write out session information to the path you have specified for writing sessions. Typically, the anonymous user is IUSR_<compname>
Magosoft
Forum Newbie
Posts: 3
Joined: Mon Feb 23, 2004 2:54 pm

Post by Magosoft »

Stoneguard wrote:Yaron,

What operating system and web server are you using?

Under Windows 2000+ you must give the anonymous user id the proper security level to write out session information to the path you have specified for writing sessions. Typically, the anonymous user is IUSR_<compname>
I have the same problem.
I'm developing with Apache 1.3.X and php-4.3.4,
under Windows 2000 professional.

In my php.ini file I had set the session_path="C:\php\sessions"
when I start the session with:

<?php
session_start();
$_SESSION['myvar]='Some string';
echo '<a href="test.php">Test</a>';
?>

This creates a file with the name:
sess_56#######.....etc.
When I edit it is says:
myvar|s:11:"Some string"
However, when I hit the Test link on my page
the value does not exists in the new page, and
it creates me a new session file in the session folder.

The code for the test.php file is:
<?php
session_start();
echo $_SESSION['myvar'];
?>

Any help will be appreciated.

MAGO
Post Reply