Jump to content

[SOLVED] HTTP_SESSION_VARS doesn't return a value


Dumps

Recommended Posts

I have used $_SESSION successfully in the past, but the server I have to use for a project is using PHP 4.0.1 so I have to use HTTP_SESSION_VARS instead.

 

I can't seem to get it to return a value for some reason. I've checked and register_globals is on.

 

If I assign a value to a HTTP_SESSION_VARS variable I can return it on the same page ok:

<?php
session_start();
$HTTP_SESSION_VARS['tester'] = "This is a test";
print "{$HTTP_SESSION_VARS['tester']}";
?>

 

outputs: This is a test

 

However, obviously this is not much use and I want to be able to use the variable on other pages - ie use it globally. If I try this on another page:

 

<?php
session_start();
print "{$HTTP_SESSION_VARS['tester']}";
?>

 

nothing is returned.

 

Essentially I've used it in the same way as I would $_SESSION without success.

 

Clearly I'm missing something - I've checked the docs and as far as I can make out this should work.

 

Can anyone point me in the right direction please?

 

 

 

Link to comment
Share on other sites

Hmmm had tried that so have tried again:

 

session_start();
global $HTTP_SESSION_VARS;
$HTTP_SESSION_VARS['tester'] = 'This is a test';

 

and

 

session_start();
global $HTTP_SESSION_VARS;
print_r ($HTTP_SESSION_VARS);

 

but still nothing. I just get Array() for the empty array.

 

Cheers anyway but any other ideas?

Link to comment
Share on other sites

register_globals is on so I've tried turning them off:

 

<?php
session_start();
ini_set('register_globals', 0);
global $HTTP_SESSION_VARS;
$HTTP_SESSION_VARS['tester'] = 'This is a test';
?>

 

and it makes no difference - other pages just return an empty array. I thought globals should be on anyway.

 

Yes, upgrading would be the simplest option but its a work box (I certainly wouldn't pay for 4.0.1) and IT are reluctant to upgrade for some reason. I am working on them, but in the meantime.......

 

This is a strange one as I've got HTTP_POST_VARS working fine, its just the session array thats the problem.

Link to comment
Share on other sites

At last I've solved this, and it was, as expected, quite simple.

 

<?php
session_start();
$test = "at last this works!!!";
session_register('test');
?>

 

and to use the session variable $test

 

<?php
session_start();
print_r($HTTP_SESSION_VARS['test']);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.