signon.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Single signon for phpMyAdmin
  4. *
  5. * This is just example how to use session based single signon with
  6. * phpMyAdmin, it is not intended to be perfect code and look, only
  7. * shows how you can integrate this functionality in your application.
  8. */
  9. declare(strict_types=1);
  10. /* Use cookies for session */
  11. ini_set('session.use_cookies', 'true');
  12. /* Change this to true if using phpMyAdmin over https */
  13. $secure_cookie = false;
  14. /* Need to have cookie visible from parent directory */
  15. session_set_cookie_params(0, '/', '', $secure_cookie, true);
  16. /* Create signon session */
  17. $session_name = 'SignonSession';
  18. session_name($session_name);
  19. // Uncomment and change the following line to match your $cfg['SessionSavePath']
  20. //session_save_path('/foobar');
  21. @session_start();
  22. /* Was data posted? */
  23. if (isset($_POST['user'])) {
  24. /* Store there credentials */
  25. $_SESSION['PMA_single_signon_user'] = $_POST['user'];
  26. $_SESSION['PMA_single_signon_password'] = $_POST['password'];
  27. $_SESSION['PMA_single_signon_host'] = $_POST['host'];
  28. $_SESSION['PMA_single_signon_port'] = $_POST['port'];
  29. /* Update another field of server configuration */
  30. $_SESSION['PMA_single_signon_cfgupdate'] = ['verbose' => 'Signon test'];
  31. $_SESSION['PMA_single_signon_HMAC_secret'] = hash('sha1', uniqid(strval(rand()), true));
  32. $id = session_id();
  33. /* Close that session */
  34. @session_write_close();
  35. /* Redirect to phpMyAdmin (should use absolute URL here!) */
  36. header('Location: ../index.php');
  37. } else {
  38. /* Show simple form */
  39. header('Content-Type: text/html; charset=utf-8');
  40. echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  41. echo '<!DOCTYPE HTML>
  42. <html lang="en" dir="ltr">
  43. <head>
  44. <link rel="icon" href="../favicon.ico" type="image/x-icon">
  45. <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
  46. <meta charset="utf-8">
  47. <title>phpMyAdmin single signon example</title>
  48. </head>
  49. <body>';
  50. if (isset($_SESSION['PMA_single_signon_error_message'])) {
  51. echo '<p class="error">';
  52. echo $_SESSION['PMA_single_signon_error_message'];
  53. echo '</p>';
  54. }
  55. echo '<form action="signon.php" method="post">
  56. Username: <input type="text" name="user" autocomplete="username"><br>
  57. Password: <input type="password" name="password" autocomplete="current-password"><br>
  58. Host: (will use the one from config.inc.php by default)
  59. <input type="text" name="host"><br>
  60. Port: (will use the one from config.inc.php by default)
  61. <input type="text" name="port"><br>
  62. <input type="submit">
  63. </form>
  64. </body>
  65. </html>';
  66. }