Page 1 of 1
Session Handling on Win2003 Server
Posted: Wed Sep 21, 2005 5:53 pm
by tbirnseth
Not sure if this is the right place to post this question but thought I'd start here. I have:
Win2003 Server with PHP5 configured through ISAPI.
When I change the php.ini file to have session.save_path = "/tmp" I get message like:
"open("/tmp\session<uglynumber>", O_RDWR) No such file or directory" from the session_start() function.
If I undefine the session.save_path in php.ini (which by the way seems to need to be in c:\windows - the %Path% seems to be ignored) then the session_start does not geneate any errors but the following code prints 'session value is:'
session_save_path("/tmp"); // Note same behavior whether this is used or not without session.save_path defined in php.ini
session_start();
$GLOBALS['ses'] = 'Test of Session';
session_register('ses');
print ' session value is:' . $_SESSION['ses'];
Any ideas how to get sessions to work correctly under Win2003 Server? I'm sure I'm missing something simple and that leaving the session.save_path = undefined is telling the system to ignore session operations.
One additonal question:
1) I'd assumed the session_save_path was relative to the doc_root so the actual directory on the system using "/tmp" as the session.save_path value equates to c:\inetpub\wwroot\website\tmp. Or does it use a system path and I should be using something like c:\temp?
Getting this stuff to play on Win2003 server is enough to get me to use ASP!
tony
Posted: Wed Sep 21, 2005 6:02 pm
by feyd
few issues:
- session_register() is a major no-no when using $_SESSION.. it is intended for register_globals on users only.. which you are not one (by default)
- you need to set session.save_path in php.ini to a writable (by the server user) temporary directory. This will allow the session system to write the files to that directory...
FYI, /tmp is a filesystem path, so it'll go to the root of the HD it's on, not a doc_root based one.
Posted: Wed Sep 21, 2005 8:15 pm
by tbirnseth
Okay, let me see if I parse your info correctly and then ask a few other questions....
I need to set the session.save_path to something like "c:\inetpub\wwwroot\SessionDir" and then create that directory so that it's writable by IUSR_PDX1 (on my server).
I'm assuming that if I call session_set_path("/tmp") from within the script then it becomes relative to the root of the URL. Please confirm.
Question on the use of session_register(). You state it's a no-no. Okay, what's the proper code sequence to use to store a user_id within the session so I can verify from other pages that the user is logged in?
Appreciate you help and responses. This all worked great in a Linux environment using Dreamweaver code segments......
tony
Posted: Wed Sep 21, 2005 8:21 pm
by feyd
tbirnseth wrote:I need to set the session.save_path to something like "c:\inetpub\wwwroot\SessionDir" and then create that directory so that it's writable by IUSR_PDX1 (on my server).
yes.
tbirnseth wrote:I'm assuming that if I call session_set_path("/tmp") from within the script then it becomes relative to the root of the URL. Please confirm.
Negatory. The path sent is a full system level path.
tbirnseth wrote:Question on the use of session_register(). You state it's a no-no. Okay, what's the proper code sequence to use to store a user_id within the session so I can verify from other pages that the user is logged in?
Code: Select all
<?php
session_start();
$_SESSION['user_id'] = 75;
?>
page 2
Code: Select all
<?php
session_start();
print_r($_SESSION);
?>
tbirnseth wrote:Appreciate you help and responses. This all worked great in a Linux environment using Dreamweaver code segments......
ack... ack.. the evil word... Linux.. hahha no.. but Dreamweaver is

For whatever reason, we've had many threads here involving DW in all its intelligence adding "invisible" characters to the start of a file, thus making life really painful when you're setting cookies among other header responses...
Posted: Wed Sep 21, 2005 9:46 pm
by tbirnseth
Okay, got it all working and code adjusted. I decided not to use the sessio_set_path() and just let the system handle it. But I thought everything called from within a session was relative to the URL root. Oh well, doesn't matter.
Just for others, here's what I ended up with:
In php.ini (WINDOWS directory) I have session.save_path = "c:\inetpub\wwwroot\SessionDir".
I made that directory full control for IUSR_PDX1 which is what web services run as on my server.
I ripped out all the dreamweaver code that did session_register() and session_unregister() and replaced them with $_SESSION['index'] = value; And changed the session_unregisters to unset($_SESSION['index']);
Now, if the installation docs would only match reality relative to the php.ini file. Also notice that a number of the extnsions cause the inetserver to simply hang. Things like php_crypt.dll and a couple of others. That was a very tedious process of change a value, stop/start w3svc, test that it doesn't hang, change a value.....
But I think I have this app working with IIS/PHP and MySQL on a Win2003 server with ASP, MSSQL, etc.... More testing to do but all looks good at this point!
Thanks so much for your patient help! And answering the naieve question(s).
tony
Posted: Thu Sep 22, 2005 2:29 am
by Maugrim_The_Reaper
In php.ini (WINDOWS directory) I have session.save_path = "c:\inetpub\wwwroot\SessionDir".
May want to consider moving your session dir below the level of your web directory - esp. if this server is live.
The "/tmp" reference is unix/linux specific - its not a relative root. The base dir of a unix system is "/", i.e. root. Unlike in Windows which refers to HD partitions by letter, i.e. C:, D:, etc.