PHP Session Variable Bug? -


i have run bizare issue php sessions driving me nuts. here gist of doing

$tout = time(); session_start(); $_session['dna'] = md5($_server['http_user_agent']); if (1 == $user->demo)      $_session['demo'] = $user->demo; $_session['tout'] = $tout; 

this appears work fine. however, variant

$tout = time(); session_start(); $_session['dna'] = md5($_server['http_user_agent']); if (1 == $user->demo)  {     $_session['demo'] = $user->demo;     $tout += 900; } else      $tout += 7200; $_session['tout'] = $tout; 

trashes entire $_session array.

briefly, trying keep track of when user session stated on each subsequent interaction server establish whether session should marked being timed out , user informed accordingly. timeout should 900s in demo mode , 7200s otherwise.

perhaps there issue integer arithmetic on 32 bit local wamp server though doubt since simple test script arithmetic , echo result works. points sort of issue storing result in session array.

this driving me round bend , sure there obvious not seeing here. appreciated.

try this..

<?php     session_start();     $_session['tout'] = time();      $_session['dna'] = md5($_server['http_user_agent']);      if (1 == $user->demo)      {      $_session['demo'] = $user->demo;      $_session['tout'] = $_session['tout'] + 10 * 60  // example 10 minutes     }      else       $_session['tout'] = $_session['tout'] + 20 * 60  // example 20 minutes ?> 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -