signon.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /* Need to have cookie visible from parent directory */
  14. session_set_cookie_params(0, '/', '', false);
  15. /* Create signon session */
  16. $session_name = 'SignonSession';
  17. session_name($session_name);
  18. // Uncomment and change the following line to match your $cfg['SessionSavePath']
  19. //session_save_path('/foobar');
  20. session_start();
  21. /* Was data posted? */
  22. if (isset($_POST['user'])) {
  23. /* Store there credentials */
  24. $_SESSION['PMA_single_signon_user'] = $_POST['user'];
  25. $_SESSION['PMA_single_signon_password'] = $_POST['password'];
  26. $_SESSION['PMA_single_signon_host'] = $_POST['host'];
  27. $_SESSION['PMA_single_signon_port'] = $_POST['port'];
  28. /* Update another field of server configuration */
  29. $_SESSION['PMA_single_signon_cfgupdate'] = array('verbose' => 'Signon test');
  30. $id = session_id();
  31. /* Close that session */
  32. session_write_close();
  33. /* Redirect to phpMyAdmin (should use absolute URL here!) */
  34. header('Location: ../index.php');
  35. } else {
  36. /* Show simple form */
  37. header('Content-Type: text/html; charset=utf-8');
  38. echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  39. ?>
  40. <!DOCTYPE HTML>
  41. <html lang="en" dir="ltr">
  42. <head>
  43. <link rel="icon" href="../favicon.ico" type="image/x-icon" />
  44. <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
  45. <meta charset="utf-8" />
  46. <title>phpMyAdmin single signon example</title>
  47. </head>
  48. <body>
  49. <?php
  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. ?>
  56. <form action="signon.php" method="post">
  57. Username: <input type="text" name="user" /><br />
  58. Password: <input type="password" name="password" /><br />
  59. Host: (will use the one from config.inc.php by default)
  60. <input type="text" name="host" /><br />
  61. Port: (will use the one from config.inc.php by default)
  62. <input type="text" name="port" /><br />
  63. <input type="submit" />
  64. </form>
  65. </body>
  66. </html>
  67. <?php
  68. }
  69. ?>