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 | declare(strict_types=1); |
||
14 | |||
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(); |
||
27 | |||
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 | $id = session_id(); |
||
38 | /* Close that session */ |
||
39 | @session_write_close(); |
||
0 ignored issues
–
show
|
|||
40 | /* Redirect to phpMyAdmin (should use absolute URL here!) */ |
||
41 | header('Location: ../index.php'); |
||
42 | } else { |
||
43 | /* Show simple form */ |
||
44 | header('Content-Type: text/html; charset=utf-8'); |
||
45 | echo '<?xml version="1.0" encoding="utf-8"?>' , "\n"; |
||
46 | ?> |
||
47 | <!DOCTYPE HTML> |
||
48 | <html lang="en" dir="ltr"> |
||
49 | <head> |
||
50 | <link rel="icon" href="../favicon.ico" type="image/x-icon" /> |
||
51 | <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" /> |
||
52 | <meta charset="utf-8" /> |
||
53 | <title>phpMyAdmin single signon example</title> |
||
54 | </head> |
||
55 | <body> |
||
56 | <?php |
||
57 | if (isset($_SESSION['PMA_single_signon_error_message'])) { |
||
58 | echo '<p class="error">'; |
||
59 | echo $_SESSION['PMA_single_signon_error_message']; |
||
60 | echo '</p>'; |
||
61 | } |
||
62 | ?> |
||
63 | <form action="signon.php" method="post"> |
||
64 | Username: <input type="text" name="user" /><br /> |
||
65 | Password: <input type="password" name="password" /><br /> |
||
66 | Host: (will use the one from config.inc.php by default) |
||
67 | <input type="text" name="host" /><br /> |
||
68 | Port: (will use the one from config.inc.php by default) |
||
69 | <input type="text" name="port" /><br /> |
||
70 | <input type="submit" /> |
||
71 | </form> |
||
72 | </body> |
||
73 | </html> |
||
74 | <?php |
||
75 | } |
||
76 | ?> |
||
77 |
If you suppress an error, we recommend checking for the error condition explicitly: