-1

COOKIES that i get back from the server it's as if my browser does not save this PHPSESID cookie

This is my index.php :

<?php
  session_start();
  require_once 'bootstrap.php';


 if(session_id()==''){

     $_SESSION["var"] = 12;
 }
 else echo $_SESSION['var'];


it does not return anything, how can this be ?

1 Answers1

0

You need to call session_start(); on every page you want use $_SESSION

<?php
  require_once 'bootstrap.php';
  session_start();

  if(!isset($_SESSION["var"])){
     $_SESSION["var"] = 12;
  }
  else {
     echo $_SESSION['var'];
  }

DE_
  • 113
  • 7
  • _You need to call session_start(); on every page you want use $_SESSION_ The correct place is at the top of each script – B001ᛦ May 28 '20 at 17:00
  • Yea, only the scripts that you need to use $_SESSION – DE_ May 28 '20 at 17:01
  • Thank you for reply. This is the only page I use at the moment. Your code still doesn't return 12, do you have an idea what this can be? Is there anything else that I'm missing ? – Balsa Popovic May 28 '20 at 17:02
  • Yea i still don't get 12. Could it be something in my php installation? – Balsa Popovic May 28 '20 at 17:07
  • Is it possible you already set $_SESSION["var"] to a blank or null value? If you did then it wouldn't show anything. Closing your browser will reset the session. – DE_ May 28 '20 at 17:10
  • @DE_ Safest to add it to all pages, then its access gets updated by every page, so it does not get removed because you were not using the couple of pages that need it for some time but were still on the site – RiggsFolly May 28 '20 at 17:17
  • This is the only page I'm using there is no more code, and i have found i temp folder every session that i have created with the VARIABLE : 12 My question is why my browser doesn't save PHPSESSID COOKIE it gets ? – Balsa Popovic May 28 '20 at 17:26