PHP Session Variable get lost and session id is changing on every request -


i found many answers problem nothing solved problem - want show code , hope can find mistake..

i have standard html formular gives data post next .php file , save session-variables. use session variables 2 reasons:

  1. if reloads page, should show same information before.
  2. i need variables in upcoming php files.

here code:

   session_start();    // handle variables on post , reloaded-page   if(isset($_post["locid"]) && isset($_post["dateid"]) )   {        $locid  = htmlspecialchars($_post["locid"]);       $dateid = htmlspecialchars($_post["dateid"]);        $_session["locid"]    =   $locid;       $_session["dateid"]   =   $dateid;        echo "session variables set: locid = " . $_session["locid"] . " dateid = " . $_session["dateid"];    } elseif(isset($_session["locid"]) && isset($_session["dateid"])) {        echo "get session";       $locid    =   $_session["locid"];       $dateid   =   $_session["dateid"];     } else {        $load_error = 1;       $status = "alert alert-danger";       $message = "shit, no variables here";    } 

the frist call works fine - session variables set , echo gives right values. after reloading page echo "get session" variables have no values.

i checked session_id() on first call , reload.. not same.

i testet simple test.php file start session variable , ask variable in next file. works fine :-/

its problem code above. think webserver handling right. reasons there chaging session id , losing session-variable values?

well, mistake quite easy find. in fact, code works perfectly. @ part:

  echo "get session";   $locid    =   $_session["locid"];   $dateid   =   $_session["dateid"]; 

well, asign session values 2 variables, in fact, missed output them anywhere. thats why "get session" displays nothing, need echo them.

simply add echo , display vars :)

echo "get session"; $locid    =   $_session["locid"]; $dateid   =   $_session["dateid"];  echo $locid; echo $dateid; 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -