Dumps Posted September 6, 2007 Share Posted September 6, 2007 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? Quote Link to comment Share on other sites More sharing options...
thedarkwinter Posted September 6, 2007 Share Posted September 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
xyn Posted September 6, 2007 Share Posted September 6, 2007 use $_SESSION['tester'] instead? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 6, 2007 Share Posted September 6, 2007 Also, keep in mind sessions last for the subdomain. http://site.com will have a different sessionID than http://www.site.com Quote Link to comment Share on other sites More sharing options...
Dumps Posted September 6, 2007 Author Share Posted September 6, 2007 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 6, 2007 Share Posted September 6, 2007 Use $_SESSION. Quote Link to comment Share on other sites More sharing options...
Dumps Posted September 7, 2007 Author Share Posted September 7, 2007 I didn't think you could use $_SESSION on anything earlier than PHP 4.1.0. and I have to use 4.0.1 (this is beyond my control). Still stuck - I'm sure there must be a simple explanation / something basic I'm missing....? Quote Link to comment Share on other sites More sharing options...
jitesh Posted September 7, 2007 Share Posted September 7, 2007 check in php.ini "register_long_arrays" is On + Restart Webserver Quote Link to comment Share on other sites More sharing options...
Dumps Posted September 7, 2007 Author Share Posted September 7, 2007 According to the documentation that directive only became available with version 5 and I'm unfortunately having to use 4.0.1. Thanks anyway but no joy there. Hmmmm, this is a knotty one..... Quote Link to comment Share on other sites More sharing options...
xyn Posted September 7, 2007 Share Posted September 7, 2007 Hm I don't know if this is the problem. but you coudl check if globals are turned off. if so you will need to turn them on! ini_set('register_globals', 1); Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 7, 2007 Share Posted September 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
xyn Posted September 7, 2007 Share Posted September 7, 2007 Well i suggest trying it with globals ON. if it works then globals is your problem if no change, turn them off and we can think of another way! Quote Link to comment Share on other sites More sharing options...
Dumps Posted September 7, 2007 Author Share Posted September 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
xyn Posted September 7, 2007 Share Posted September 7, 2007 oh i know try... {$_SERVER['HTTP_SESSION_VARS']['tester']} Quote Link to comment Share on other sites More sharing options...
xyn Posted September 7, 2007 Share Posted September 7, 2007 Or. failing then print_r($_SERVER['HTTP_SESSION_VARS']); Quote Link to comment Share on other sites More sharing options...
Dumps Posted September 7, 2007 Author Share Posted September 7, 2007 Nope no joy with that - it just returns an empty array. This is somewhat perplexing. ??? Quote Link to comment Share on other sites More sharing options...
Dumps Posted September 10, 2007 Author Share Posted September 10, 2007 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']); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.