<?php

foreach ($_POST as $key => $value) {
    echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
}

$session_name = 'SignonSession';
session_name($session_name);

$_SESSION['PMA_single_signon_user'] = $_POST['user'];
$_SESSION['PMA_single_signon_password'] = $_POST['password'];

header('Location: index.php');

die();

/**
 * Single signon for phpMyAdmin
 *
 * This is just example how to use session based single signon with
 * phpMyAdmin, it is not intended to be perfect code and look, only
 * shows how you can integrate this functionality in your application.
 */

//declare(strict_types=1);

/* Use cookies for session */
//ini_set('session.use_cookies', 'true');
/* Change this to true if using phpMyAdmin over https */
//$secure_cookie = false;
/* Need to have cookie visible from parent directory */
//session_set_cookie_params(0, '/', '', $secure_cookie, true);
/* Create signon session */
//$session_name = 'SignonSession';
//session_name($session_name);
// Uncomment and change the following line to match your $cfg['SessionSavePath']
//session_save_path('/var/lib/php/session');
//@session_start();

/* Was data posted? */
if (isset($_POST['user'])) {
    /* Store there credentials */
    $_SESSION['PMA_single_signon_user'] = $_POST['user'];
    $_SESSION['PMA_single_signon_password'] = $_POST['password'];
    $_SESSION['PMA_single_signon_host'] = $_POST['host'];
    $_SESSION['PMA_single_signon_port'] = $_POST['port'];
    /* Update another field of server configuration */
    $_SESSION['PMA_single_signon_cfgupdate'] = ['verbose' => 'Signon test'];
    $_SESSION['PMA_single_signon_HMAC_secret'] = hash('sha1', uniqid(strval(random_int(0, mt_getrandmax())), true));
    $id = session_id();
    /* Close that session */
   // @session_write_close();
    /* Redirect to phpMyAdmin (should use absolute URL here!) */
    header('Location: index.php');
} else {
    /* Direct to login page */
    echo "Post wasn't detected <br>";
    foreach ($_POST as $key => $value) {
        echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
    }
    // header('Location: ../login.php');
}
