2

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!

4
  • Do you happen to be using variables named $userid and $hash elsewhere in the script? Commented Apr 8, 2010 at 19:19
  • Does the same call occur in the same script? Before the second call to print_r do you by any way unset Session variables? Do you use a component or library that might be using the same hashes for user authentication ('userid' and 'hash') ? (make sure you have globals disabled) Commented Apr 8, 2010 at 19:22
  • I use many different scripts. but the first print_r is at the very beginning, right after session_start(), and the second print_r is followed by exit() Commented Apr 8, 2010 at 19:34
  • I have the same problem, could you solve your problem? Commented Feb 8, 2014 at 19:57

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for answering my question. I renamed the variables to some arbitrary value, but nothing changed
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.