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?

 

 

 

Hi

 

if im not mistaken, http_session_vars is not superglobal, so you have to use the global directive to access if:

 

<?php
session_start();
global $HTTP_SESSION_VARS;
print_r ($HTTP_SESSION_VARS);
?>

 

cheers,

tdw

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?

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

 

leave globals off....

 

why not just upgrade the php engine?

 

If I were paying for hosting with php 4.0.1 on I'd be very upset! If I had control over teh box I'd install later version myself.

 

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.

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']);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.