0

I wrote a simple php(html) script to show me a status. Via JQUERY the status update happen automatically. A few parameters are provided from another script and sent via GET to the status script. So the idea was to use S_SESSION

    if( session_status() == PHP_SESSION_NONE ) // if session status is none then start the session
{
    session_start();
    $_SESSION['dur'] = 10;
    $_SESSION['gDur'] =  0;
}else{
    error_log("ShowListeners Session: " . var_export($_SESSION, true),0);
}
if(isset($_GET['dur'])){
    error_log("ShowListeners GET: " . var_export($_GET, true) , 0);
    $_SESSION['dur'] = $_GET['dur'];
    $_SESSION['gDur'] =  $_GET['gDur'];
}

In the part where I try to read the session data

    if(isset($_SESSION['dur']))
        $ret .= getTimeString($_SESSION['dur']);

$_SESSION['dur'] is always not existing. I also can see, that every time the script is called, session_start() is called because I can not see any error_log!

Do I something wrong or is it not possible to store the data in a session variable?

Edit(2021-08-08)

In the meantime I have read a lot about SESSION. I understand, that SESSION are related to users or cookies. But what is not clear to me, is there any possibility to make sure, that several instances can access the same SESSION data? For example, there is a instance running and another instance get over GET an data update. Can this instance access and modify the SESSION date used by the first instance?

Georgio
  • 129
  • 1
  • 10

1 Answers1

0

I think that your first condition scope can be the cause of your problem..., why don't you call "session_start()" everytime ?

Here's my proposition that you can try :

session_start();
if(!isset($_SESSION['dur'])) {

    $_SESSION['dur'] = 10;
    $_SESSION['gDur'] =  0;
}
if(isset($_GET['dur'])) {

    $_SESSION['dur'] = (int) $_GET['dur'];
    $_SESSION['gDur'] = (int)  $_GET['gDur'];
}
moDevsome
  • 189
  • 2
  • 16
  • OK it is working for the new instance. But I want to send these data to all instances, which are already running. Is this possible? – Georgio Aug 07 '21 at 13:17
  • every client has a different session; if you want to share across all, you might have to look into using redis and on all request you read the same key from redis –  Aug 07 '21 at 15:30