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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP sessions failing

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
Hi All,

In my php app I am using sessions on a win2k machine with php as cgi. The sessions don't seem to keep alive across different pages and if I call the session_start() on each page then I get a new session.

I think it might be something in the set up of where the sessions are stored on the machine...right now it is in c:/windows/temp...

does anyone have any ideas here?

TIA
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
I'm not sure about the ramifications of using php as a cgi, which begs the question: why aren't you using it as a module?
I am using php as an Apache module on Win98. Here are the configuration lines from my php.ini (comments removed):
Code:
[Session]
Code:
session.save_handler = files
session.save_path = C:\Windows\temp
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_maxlifetime = 1440
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 1
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Also, how are you referencing your session variables? If
Code:
register_globals
is turned off in your php.ini, you have to use
Code:
$_SESSION["value name"]
. I would recommend doing it that way regardless of the
Code:
register_globals
setting though.

Read up on it:
(there are some very nice juicy things to be found here)

Have fun! :)
 
I am having a great deal of trouble with maintaining a session across several pages...(win2k / iis / php)

I have the following code:

session_start();
if (!$PHPSESSID){
session_register('ip');
$ip=$REMOTE_ADDR;
}else if (!$ip){
session_register('ip');
}
//rest of the code


in every page that needs to reference the session, currently 3 but gonna need 4 or 5 pages total. The code goes like this, I start a session, the data get passed to the next page and inserted into the DB. When I go back to the original products page, a new session is started and a new session_id is created...

any ideas why i can't get the session to remain?

TIA
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
I see no point in that excersize!

if you want session, they are easy!

session_start();
session_register("data");

Then to read OR write use $_SESSION['data']

you can even store arrays in there! --BB
 
1. Did you check
Code:
register_globals
in your php.ini?
2. When you use
Code:
$_SESSION
autoglobal, you don't need to use the
Code:
session_register()
function, just set all the data you need into it's respective
Code:
$_SESSION
node.
3. Have you tried using the
Code:
$_SESSION
autoglobal?
4. Did you compare your php.ini settings to the ones I posted?
5. Why are you using PHP as a CGI rather than a module?

If we can rule all these things out, we'll need to look somewhere else for the problem, but look at this stuff first. It's most definitely one of those things.
 
I'm having a similar problem using sessions on Win2K w/Apache (not as CGI). The first line of code on both pages is session_start(). I unset($_SESSION["sesValue"]) at the top of the first page. When the second page loads it branches based on if(isset($_SESSION["sesValue"])). if it is not set the second page is a form where the user fills in some fields and the form calls the second page again (itself). The second time page 2 is called it uses the form value to set the session value
[tt]
if (isset($_GET["formValue"])
{
$_SESSION["sesValue"] = $_GET["formValue"];
}
[/tt]
then puts the second page in an edit mode as opposed to an add mode.

When the user is finished editing they are returned to the first page, which unsets the session value. The user goes to page 2 again to add another value and instead they are put in edit mode because for some reason the session value on the second page still seams to be set? I put in a bunch of echos to check the value of $_SESSION["sesValue"] on both pages and on the first I get an error that sesValue is not a valid index (which is what I expect since I start the first page by unsetting the session value. However the second page always shows me the value that was set the first time through the page. The unset does not seem to carry to the second page.
 
Hey sonnysavage

1. Did you check register_globals in your php.ini?

Yes... is set to on

2. When you use $_SESSION autoglobal, you don't need to use the session_register() function, just set all the data you need into it's respective $_SESSION node.

$_SESSION gives me the same problem...loses the session and then starts a new one...could it be something to do with setting the cache to no-cache?

3. Have you tried using the $_SESSION autoglobal?
4. Did you compare your php.ini settings to the ones I posted?

ini file looks pretty much the same...will take another look

5. Why are you using PHP as a CGI rather than a module?
CGI is best for w2k/iis...

Driving me nuts, most of the rest of the app works and this is what is holding me up....

TIA

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Bastien:
The only thing I can come up with based on this is the
Code:
session.save_path
, you are using forward slashes (/), while I am using back slashes (\). Try changing that.

tonedef:
You need to post more of your code since it sounds like a code bug and not a session problem. You should start a new thread with this question, so more people will look at it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top