[solved] Session Variables not working

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK. Thanks for clearing it all up for me on session id. I don't use it much (can you tell?). I usually use DB sessions.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Feyd,

Hi here is the results of the output of the code you gave me:

Code: Select all

PHP Version: 4.3.2-RC2
PHP OS: WINNT
Error Reporting: 2047 (E_ALL)
Register Globals: On
Short Tags: On
Display Errors: Off
Does that tell us anything?

Rob.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Everah here are the results of your tests..........

test.php:

Code: Select all

ROB is the value set for "test".
Our current session id is 00e6b5525f41a6b04e0dbcfcea719526
Try the test
test2.php

Code: Select all

is the value set for "test".
Our current session id is 00e6b5525f41a6b04e0dbcfcea719526
Confused? Yes I am !

Rob.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That is odd. It seems to be keeping some session data but not other data. :?: That means sessions are working. But why they would not be working on your variables is confusing.

Is this portion of code executing after an include or other code that could potentially unset or reset the session var?

EDIT: OOhh, maybe something else you can try... On your first test page set like four or five session vars. On the second of the two test which values you have using a for each loop...

Code: Select all

<?php
foreach ($_SESSION as $key => $value) 
{
    echo $key .  ' is the session key and ' . $value . ' is its value.<br />';
}
?>
See what that throws at you.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

There are no includes, the code as it is in two simple files with no other text or lines of code.

Rob.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK, run the test that I added to my last post. If that does nothing post the full code of both pages. Also, try running a stripped down version ofthe two pages for testing, making sure to write them fresh (not reusing any code from the two current pages). And try clearing your cache again to make sure you are seeing the freshest page renders.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here is my code exactly as it is in the files, the 2nd page displays nothing just a white screen......

1:

Code: Select all

<?php
session_start();
$_SESSION['test1']="ROB";
$_SESSION['test2']="ROB";
$_SESSION['test3']="ROB";
$_SESSION['test4']="ROB";
$_SESSION['test5']="ROB";
$_SESSION['test6']="ROB";
echo $_SESSION['test1'] . ' is the value set for "test1".<br />';
echo $_SESSION['test2'] . ' is the value set for "test2".<br />';
echo $_SESSION['test3'] . ' is the value set for "test3".<br />';
echo $_SESSION['test4'] . ' is the value set for "test4".<br />';
echo $_SESSION['test5'] . ' is the value set for "test5".<br />';
echo $_SESSION['test6'] . ' is the value set for "test6".<br />';
echo 'Our current session id is ' . session_id() . '<br />';
echo '<a href="test2.php">Try the test</a>';
?>

2:

Code: Select all

<?php
session_start();
foreach ($_SESSION as $key => $value) 
{
    echo $key .  ' is the session key and ' . $value . ' is its value.<br />';
}
?>

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Change the second page to this:

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
session_start();
foreach ($_SESSION as $key => $value)
{
    echo $key .  ' is the session key and ' . $value . ' is its value.<br />';
}
?>
Then clear the cache and run the second page again by way of a link from the first page. See what that does.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Hi,

I posted the 2nd script exactly as you said and I still get a blank white screen........

You can test and view the source here:

http://www.first4glass.net/test1.php

This is very odd!

Rob.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Since display errors is off, you should check your error logs.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Ok maybe we are getting some where now........

Here is the error log:

Code: Select all

[Wed Apr 12 08:46:44 2006] [error] PHP Warning:  session_start(): open(/tmp\sess_d509fff503b0bca31d6d115b91e81725, O_RDWR) failed: No such file or directory (2) in d:\software\apache\htdocs\first4glass\test1.php on line 2
[Wed Apr 12 08:46:44 2006] [error] PHP Warning:  Unknown(): open(/tmp\sess_d509fff503b0bca31d6d115b91e81725, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
[Wed Apr 12 08:46:44 2006] [error] PHP Warning:  Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
Rob.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

So the first thing you do is type the message in a search-engine (or this forum) and you get plenty of solutions..

(/tmp doesn't exist on windows so change the session.save_path to c:/temp or whatever...)
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Fantastic guys, thanks for your help.

I guess I have learnt to check my error logs,just had to change the dir of the temp folder, working perfectly now.

Many thanks again!

Rob.
Post Reply