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