Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have no session

Status
Not open for further replies.

Greenster

Programmer
Jan 14, 2002
30
GB
Please help me - php keeps losing my session. I include a config file at the top of every script with this code.

if(!isset($HTTP_SESSION_VARS['session'])){
session_register('session');
$HTTP_SESSION_VARS['session'] = array();
}
session_start();

But every time I re-load the page my session is lost. I appear to have tmp sessions in the /tmp folder

Please help - what am I doing wrong?

Thank you

{Greenster}
 
I've had trouble with sessions in a couple of instances that sound familiar...

One, in local functions or in calls to included functions, be sure to declare 'global $HTTP_SESSION_VARS' with the function before reading/assigning. This methodology was somewhat changed in v4.1.0+ to ($_sessions) so your mileage may vary.

Also, when using 'session_unregister' within an included function (a code library of mine) I found that I needed to write

session_unregister(&$HTTP_SESSION_VARS["key"]);

I read the tip on using the "&$" someone in php.net and it turned out to be necessary for my application. You may find that it applies to the session_register as well.
 
session_start MUST BE before the register of the vars and before any HTML code. Not even a blank space in the output can be before the session_start.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
I have now got this code at the very top of the script:

session_start();
session_register('session');
ini_set('session.use_trans_sid','1');
session_name('session');
$hsv =& $HTTP_SESSION_VARS;

Line 46: $details =& $hsv['session']['details'];

I get this error:
Fatal error: Cannot create references to/from string offsets nor overloaded objects in siteconf.inc on line 46

How comes I now have this error. This code works on my local machine, is it a server setting or bad syntax??
Any help would be most appreciated.

{Greenster}
 
- there should not be spaces between "&" and "$"
- session_name must appear before session_start
- your use of &$HTTP_SESSION_VARS as a reference isn't necessary here since you're assigning their values to your own array. Remove "&" unless you're making an assignment within a called function.

'luck
 
Hi again, thanx for your last couple of posts thedaver but I am now inclined to think this is not a problem with my code. I don't get the fatal error anymore but I still can't retain my session. The PHPSession ID appended to my querystring is identical to the sess_{session_id} file in my /tmp folder and when I refresh the page NO NEW Session files are made, yet my session variables are always unset??

thedaver, could you show me exactly how you would create a session and then refernce to it in your php scripts please?

I would be most grateful for anymore help.

{Greenster}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top