PHP session not showing correctly in terminal


Zoric

I'm currently building a small script for a cron job, I'm testing everything in the terminal (Linux), but I can't figure out why the session isn't working.

session_start()
$_SESSION['cron'] = 'test';
echo $_SESSION['cron'];
Zoric

Here is my solution

private function get($key){
    $content = @file_get_contents( __DIR__ . '/../../cron/data.json' );
    if ($content) {
        $content = json_decode($content, true);
        if ( is_array($content)) {
            return $content[$key];
        }else{
            return false;
        }           
    }else{
        return false;
    }
}

private function request($key){
    $content = @file_get_contents( __DIR__ . '/../../cron/data.json' );
    if ($content) {

        $content = json_decode($content, true);
        if ( is_array($content)) {
            $content[$key] = time();
            file_put_contents( __DIR__ . '/../../cron/data.json' , json_encode($content) );
        }else{
            return false;
        }

    }else{
        file_put_contents( __DIR__ . '/../../cron/data.json' , json_encode(['demo' => time()]) );
    }
}

Related


Ncurses not showing window borders correctly in gnome terminal

Odin I'm learning how to use ncurses, and I've noticed that, for some reason, in gnome-terminal (on arch), ncurses' window borders don't display correctly. It seems to work fine in xterm. Not sure what's causing it, and I haven't had any luck. Any ideas? Odin

Ncurses not showing window borders correctly in gnome terminal

Odin I'm learning how to use ncurses, and I've noticed that, for some reason, in gnome-terminal (on arch), ncurses' window borders don't display correctly. It seems to work fine in xterm. Not sure what's causing it, and I haven't had any luck. Any ideas? Odin

PHP $_SESSION variable not showing value

Nikola Knežević: I have written a text in the page title with the name of the logged in user. It worked for a while, but when I went to do something else, it just stopped. It 's like $_SESSION['ime'] holds a null value; I'm sure I'm not hitting anything relate

PHP $_SESSION variable not showing value

Nikola Knežević: I have written a text in the page title with the name of the logged in user. It worked for a while, but when I went to do something else, it just stopped. It 's like $_SESSION['ime'] holds a null value; I'm sure I'm not hitting anything relate

How to hide computer name from showing in terminal session screen

underground dog As you can see from the screenshot, whenever I invoke a terminal session, my entire computer name (looks like a key) is displayed. Is there any way to avoid or hide it? Radu Rădeanu Yes. Open the file from the terminal with the following comman

How to hide computer name from showing in terminal session screen

underground dog As you can see from the screenshot, whenever I invoke a terminal session, my entire computer name (looks like a key) is displayed. Is there any way to avoid or hide it? Radu Rădeanu yes. Open the file from the terminal with the following comman

PHP uses session_start correctly

backspace When the web application starts, it will connect to the DB and store the information as session variables. Only get the data at the start of the application. The problem is that the user list is also a session variable. So, in login.php session_start

OO Mysqli PHP data not showing correctly

Lancet I am trying to display information in a table using a while loop, but if there is only 1 result, the table will not display anything. If greater than 1, the result -1 will be displayed. For example, for 5 results, it will only show 5. My query is: $quer

OO Mysqli PHP data not showing correctly

Lancet I am trying to display information in a table using a while loop, but if there is only 1 result, the table will not display anything. If greater than 1, the result -1 will be displayed. For example, for 5 results, it will only show 5. My query is: $quer

PHP Laravel session flash alert message not showing

ST80 In my- laravelapp, the user can subscribe to a checkbox on the address book. When the checkbox is checked and the form is submitted, there is a check in the controller, if the user is subscribed, and if so, a flashing alert/message with something like "yo

PHP Laravel session flash alert message not showing

ST80 In my- laravelapp, the user can subscribe to a checkbox on the address book. When the checkbox is checked and the form is submitted, there is a check in the controller, if the user is subscribed, and if so, a flashing alert/message with something like "yo

Session message not showing after using prepared statement in php

Oh St statement Session messages are not showing on the main page (main.php) Assuming includes. (Establish a connection to the MySQL server)connection.php i tried In the following code from this , I have if-else statements to check for unique duplicate entries

Session message not showing after using prepared statement in php

Oh St statement Session messages are not showing on the main page (main.php) Assuming includes. (Establish a connection to the MySQL server)connection.php i tried In the following code from this , I have if-else statements to check for unique duplicate entries

changing session not changing session correctly

username I am using an Oracle database for a project. I am inserting data into a table of the following structure CREATE TABLE targetCustord( cust_code VARCHAR2(4), order_date DATE, product_code VARCHAR2(8), order_id NUMBER, product_price NUMBER(8,2), product_

changing session not changing session correctly

username I am using an Oracle database for a project. I am inserting data into a table of the following structure CREATE TABLE targetCustord( cust_code VARCHAR2(4), order_date DATE, product_code VARCHAR2(8), order_id NUMBER, product_price NUMBER(8,2), product_

changing session not changing session correctly

username I am using an Oracle database for a project. I am inserting data into a table of the following structure CREATE TABLE targetCustord( cust_code VARCHAR2(4), order_date DATE, product_code VARCHAR2(8), order_id NUMBER, product_price NUMBER(8,2), product_