Merge pull request #19251 from MoonE/fix-gis-visualization
[phpmyadmin.git] / examples / signon.php
blob3d3dd0b0fa2d9c28233d6dda704c1321501d51db
1 <?php
2 /**
3 * Single signon for phpMyAdmin
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 */
10 declare(strict_types=1);
12 /* Use cookies for session */
13 ini_set('session.use_cookies', 'true');
14 /* Change this to true if using phpMyAdmin over https */
15 $secureCookie = false;
16 /* Need to have cookie visible from parent directory */
17 session_set_cookie_params(0, '/', '', $secureCookie, true);
18 /* Create signon session */
19 $sessionName = 'SignonSession';
20 session_name($sessionName);
21 // Uncomment and change the following line to match your $cfg['SessionSavePath']
22 //session_save_path('/foobar');
23 @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'] = ['verbose' => 'Signon test'];
34 $_SESSION['PMA_single_signon_HMAC_secret'] = hash('sha1', uniqid(strval(random_int(0, mt_getrandmax())), true));
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');
43 echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
44 echo '<!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>';
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>';
60 echo '<form action="signon.php" method="post">
61 Username: <input type="text" name="user" autocomplete="username" spellcheck="false"><br>
62 Password: <input type="password" name="password" autocomplete="current-password" spellcheck="false"><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>';