Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions on IIS 1

Status
Not open for further replies.

ArtWerk

Programmer
Jul 31, 2006
66
US
My sessions variables are not sticking on a Windows IIS server.

I use
Code:
session_start();
$_SESSION['blah'] = "no longer empty";
and
Code:
if(empty($_SESSION['blah'])){
  echo "empty session variable";
} else {
  echo $_SESSION['blah'];
}

output: empty session variable

PHP.INI Settings
Code:
session.save_handler = files
session.save_path = "P:\PHP\Sessions
session.use_cookies = 1
session.name = MY_SESSION_ID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor     = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

;session.entropy_length = 16
;session.entropy_file = /dev/urandom
;session.save_path = "/tmp"

Any ideas?
 
Is the second code snippet you posted in the same script as the first snippet or in a second script?

If it's a different script, does that second script also invoke session_start()?



Want the best answers? Ask the best questions! TANSTAAFL!
 
I don't know. If I write your two snippets to a script on my server and point my browser to it, I get:

no longer empty


I recommend that you verify that no code between the two snippets is diddling the value in $_SESSION['blah']. One place to be careful of is the use of assignment operators ("=") instead of comparison operators ("==") in conditions.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Is there something before the call to session_start that might produce output to the page like a blank line or somethng ? Although you would get a Warning if there were, its a possibility if you have your server set to not diplay any warnings.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ok, give this a try:
Code:
session_start();

if(!isset($_SESSION['blah'])){
	$_SESSION['blah'] = "initial value";

	if(empty($_SESSION['blah'])){
		echo "empty session variable";
	} else {
		echo $_SESSION['blah'];
	}
} else {
	echo "session variable was already set. i didn't do anything. see for yourself:<br>";
	echo "session variable is: ".$_SESSION['blah'];
}
mine always outputs: initial value
 
The first time (after clearing cookies from my test server), the output was:

[tt]initial value[/tt]

When I refresh the page, I get:

[tt]session variable was already set. i didn't do anything. see for yourself:
session variable is: initial value[/tt]


What behavior do you see?



Want the best answers? Ask the best questions! TANSTAAFL!
 
mine always outputs: initial value
(every time i refresh)
 
i suspect that you have not set the right permissions to the directory P:/PHP/Sessions.

the IIS process owner (usually IUSR_MACHINENAME) needs read, write and modify access to this directory.

also, of course, the share needs to be available when the script is running (if P is a mapped share and not a local drive).

lastly, in my php.ini files, even on windows, i always use a forward slash for directories.
 
no. i mean a forward slash.
Code:
c:/windows/system32/drivers/etc

php shouldn't care. but I know that i fixed a bug once by doing this (i.e. unix style) and have therefore kept to the same rule ever since.

but the most likely issue is permissions across shares. of course (for an easy life) you should also make sure that if P is on a separate machine, they are also in the same AD forest or domain and the ACL.
 
Well, the drive is mapped on my machine, however from the server's perspective, P: is the name of the drive.

As far as the slashes, we were following a tutorial on how to set it up and i'm pretty sure we set up everything exactly it said in the tutorial, which means the tutorial had forward slashes as well. So those are fine then?

Also, I just remembered to check the Error Log and this is what it said:

PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (P:\PHP\Sessions
;
; where N is an integer. Instead of storing all the session files in
; /path, what this will do is use subdirectories N-levels deep, and
; store the session data in those directories. This is useful if you
; or your OS have problems with lots of files in one directory, and is
; a more efficient layout for servers that handle lots of sessions.
;
; NOTE 1: PHP will not create this directory structure automatically.
; You can use the script in the ext/session dir for that purpose.
; NOTE 2: See the section on garbage collection below if you choose to
; use subdirectories for session storage
;
; The file storage module creates files using mode 600 by default.
; You can change that by using
;
; session.save_path = N) in Unknown on line 0

Not sure what all that means...
 
This is significant:

PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (P:\PHP\Sessions

It sounds to me like jpadie is on the right track.


My advice is that if P: points back to your machine, quit using the mapped drive letter and use a real one. I don't know about you, but I'm always looking to lighten the load on my network stack.





Want the best answers? Ask the best questions! TANSTAAFL!
 
a forward slash looks like this
Code:
/
a backslash is like this
Code:
\

you have been using backslashes and i advocated the opposite.

this does not appear to be the problem in your case. it appears that the php.ini you shows us above may not be the php.ini that is being used by php. (and the one that you are using may be corrupt or badly formatted)

to be definitive please copy and paste the results from calling a script with just <?php phpinfo(); ?> in it. make sure the script is run from the directory in which you are having trouble.
 
aha. in the php.ini above, you have not closed the double quotes around the save path.

close them and then restart IIS. then try debugging again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top