PHP code example of kodi-app / kodi-session

1. Go to this page and download the library: Download kodi-app/kodi-session library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kodi-app / kodi-session example snippets


$application->run([
    // ...
    KodiConf::HOOKS => [
        // ...
        [
            "class_name" => PandabaseSessionHook::class,
            "parameters" => [
                // Optional, you have to set it when you have more Connection instance in ConnectionManager
                "connection_name"  => "default",
                
                // Optional, 'options' parameter is same as PdoSessionHandler's 'options' parameter
                "options" => [
                    // ...
                ]
            ]
        ],
        // ...
    ],
    // ...
]);

$application->run([
    KodiConf::SERVICES => [
        SessionProvider::class
    ]
]);

/** @var Session $session */
$session = Application::get("session")

// Get username value from session (same as $_SESSION["username"]). If it doesnt exist returns with "anon".
$username = $session->get("username","anon")

// Set a new username
$new_username = "john_doe";
$session->set("username",$new_username);