tags:

views:

56

answers:

3

Dear all

I'm assigning session variables by filling the $_SESSION - Array throughout my script. My problem is, that for some reason not all variables are available in the session.

here is a shortened version of my code for explaining this issue:

session_start();

print_r($_SESSION);

$_SESSION['lang']        = 'de';
$_SESSION['location_id'] = 11;
$_SESSION['region_id']   = 1;

$_SESSION['userid'] = 'eccbc87e4b5ce2fe28308fd9f2a7baf3';
$_SESSION['hash']   = 'dce57f1e3bc6fba32afab93b0c38b662';

print_r($_SESSION);

first call prints something like this:

Array
(
)
Array
(
    [lang] => de
    [location_id] => 11
    [region_id] => 1
    [userid] => eccbc87e4b5ce2fe28308fd9f2a7baf3
    [hash] => dce57f1e3bc6fba32afab93b0c38b662
)

the second call prints:

Array
(
    [lang] => de
    [location_id] => 11
    [region_id] => 1
)
Array
(
    [lang] => de
    [location_id] => 11
    [region_id] => 1
    [userid] => eccbc87e4b5ce2fe28308fd9f2a7baf3
    [hash] => dce57f1e3bc6fba32afab93b0c38b662
)

As you can see, the important login information is not stored in the session. Does anybody has an idea what could be wrong with my session? Thanks for your answers!

+1  A: 

Further expanding on what Pekka might be alluding to, if you have register globals on there may be a naming conflict with your session variables and other variables in your script. If possible turn register globals off or rename your variables they don't collide ($_SESSION'hash'] and $hash) and see what happens.

John Conde
thanks for answering my question. I renamed the variables to some arbitrary value, but nothing changed
Flurin Juvalta
A: 

Hi, I now tried to assign the same variables ad different positions and scripts, sometimes the variable is stored in the session and sometimes not... by now I did not get any rule.

Any Ideas? Thanks for your answers

Flurin Juvalta
A: 

Paste this code, untouched, in a single script and run it several times. You should get the same results the 2nd, 3rd, 4th... time.

<?php
session_start();

print_r($_SESSION);

$_SESSION['lang']        = 'de';
$_SESSION['location_id'] = 11;
$_SESSION['region_id']   = 1;

$_SESSION['userid'] = 'eccbc87e4b5ce2fe28308fd9f2a7baf3';
$_SESSION['hash']   = 'dce57f1e3bc6fba32afab93b0c38b662';

print_r($_SESSION);
?>

If it works, then you obviously have something wrong in your script that you are not posting. In that case you should provide more code in order to be able to help you.

Danny Herran