Serious problem with sessions

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

Post Reply
suesicus
Forum Newbie
Posts: 7
Joined: Mon May 05, 2003 6:43 am

Serious problem with sessions

Post by suesicus »

I've read "Before Post Read: Sessions with a Minor in User Logins" and I've tried the example there on my computer. But something is seriously wrong anyway..

on page1.php the session works fine.. but when I move on to page2.php and so on the session is lost.

I have ver 4.3.1 of PHP so I have to use the superglobals but they won't work for me.

Anyone who knows what the problem might be?

The code for these two pages is:

--- page1.php ---

Code: Select all

<?php 

session_start(); 


if ( !isset($_SESSION&#1111;'username']) ) &#123; 
   $_SESSION&#1111;'username'] = 'jason'; 
&#125; 

echo '$_SESSION&#1111;username] equals '.$_SESSION&#1111;'username']; echo '<br><br><a href="page2.php">Go to page 2</a>'; 

?>
The first page prints:

$_SESSION[username] equals jason

Go to page 2


--- page2.php ----

Code: Select all

<?php 

session_start(); 

echo '$_SESSION&#1111;username] equals '.$_SESSION&#1111;'username']; // This doesn't work!!
echo '<br><br><a href="page3.php">Go to page 3</a>'; 

?>
The second page prints:

$_SESSION[username] equals

Go to page 3
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

although assuming you already have checked all error/warning messages you might try

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
session_start();
...
?>
maybe php is set up to use cookies for session management (default setting) and the browser is blocking them all? What happens if you replace
<?php
session_start();
...
?>
by

Code: Select all

<?php
ini_set('session.use_trans_sid', TRUE); session_start(); 
...
?>
suesicus
Forum Newbie
Posts: 7
Joined: Mon May 05, 2003 6:43 am

Post by suesicus »

ok.. thanks for helping.. I tried to check for errors and it looks like it can't find the folder to store the temporary sessions. Where should this folder be located? I've installed PHP in c:\inetpub\php.

The complete fail-message reads:

Warning: session_start() [function.session-start]: open(/tmp\sess_9f1d4fea7ca1fe682f62a01f0e1b5e07, O_RDWR) failed: No such file or directory (2) in c:\inetpub\wwwroot\Nordic2003\page1.php on line 4
$_SESSION[username] equals jason

Go to page 2
Warning: Unknown(): open(/tmp\sess_9f1d4fea7ca1fe682f62a01f0e1b5e07, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

so you're probably working on a win32 system
http://www.php.net/manual/en/ref.session.php#ini.session.save-path
Note: Windows users have to change this variable in order to use PHP's session functions. Make sure to specify a valid path, e.g.: c:/temp.
can be done in the php.ini and it can be any directory the webserver-account is able to read/write.
suesicus
Forum Newbie
Posts: 7
Joined: Mon May 05, 2003 6:43 am

Post by suesicus »

.. and my problem is solved!

Thanks!
Post Reply