signon.php 2.5 KB

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