重定向到ridirect页面后无法发送会话

时间:2019-07-02 05:46:34

标签: php

我无法从登录名和我的php版本PHP 7.3.6 (cli) (built: May 29 2019 12:12:14) ( NTS MSVC15 (Visual C++ 2017) x64 )

中获取会话

这是我的仪表板:

<?php
if (session_status() == PHP_SESSION_NONE) {
    @session_start();
    if (isset($_SESSION["username"]) && isset($_SESSION["password"])) {
?><html><head><link rel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons"><link href="https://fonts.googleapis.com/css?family=Russo+One&display=swap"rel="stylesheet"><link rel="stylesheet"href="../style/css/material.css"><link rel="stylesheet"href="../style/css/responsive.css"><script defer src="../style/js/material.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script></head><body><div class="mdl-layout mdl-js-layout mdl-layout--fixed-header"><header class="mdl-layout__header"><div class="mdl-layout__header-row"><a href="#!"><img class="image-responsive"src="../aksibox.png"></a><div class="mdl-layout-spacer"></div><nav class="mdl-navigation"><button id="logout"class="mdl-button mdl-js-button mdl-button--icon"><i class="material-icons icon-color">account_circle</i></button><script>$(function(){$("ul#logout").click(function(){<?php
        require '../aksibox/logout/AksiBoxLogout.php';
        $is = new AksiBoxLogout();
        $is->logout();
?>})})</script><ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect"for="logout"id="logout"><li class="mdl-menu__item">Logout</li></ul></nav></div><div class="mdl-layout__tab-bar mdl-js-ripple-effect"><a href="#scroll-tab-1"class="mdl-layout__tab is-active">Tambah Barang</a> <a href="#scroll-tab-2"class="mdl-layout__tab">Cari Barang</a> <a href="#scroll-tab-3"class="mdl-layout__tab">Modif Barang</a> <a href="#scroll-tab-4"class="mdl-layout__tab">Update Barang</a> <a href="#scroll-tab-5"class="mdl-layout__tab">Hapus Barang</a> <a href="#scroll-tab-6"class="mdl-layout__tab">Buat Invoice</a></div></header><main class="mdl-layout__content"><section class="mdl-layout__tab-panel is-active"id="scroll-tab-1"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><div class="mdl-textfield name-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="nameBarang"><label class="mdl-textfield__label"for="nameBarang">Nama Barang</label></div><div class="mdl-textfield code-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="codeBarang"><label class="mdl-textfield__label"for="codeBarang">Code Barang</label></div><div class="mdl-textfield value-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"pattern="-?[0-9]*(\.[0-9]+)?"id="valueBarang"><label class="mdl-textfield__label"for="valueBarang">Value Barang</label><span class="mdl-textfield__error">Input is not a number!</span></div><div class="mdl-textfield description-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="descriptionBarang"><label class="mdl-textfield__label"for="descriptionBarang">Deskripsi Barang</label></div><button class="mdl-button button-add mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"id="button-add">Add</button><div class="response-add">Berhasil menambahkan barang.</div></form></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-2"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><script>$(function(){$("input#search").keyup(function(){$(this).val()?$("button#search").show():$("button#search").hide()})})</script><div class="mdl-textfield search-box mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="search"> <button id="search"class="mdl-button search-button mdl-js-button mdl-button--icon"><i class="material-icons search-icon">search</i></button><label class="mdl-textfield__label"for="search">Nama atau Kode barang</label></div></form><div class="response-search">Data barang yang di temukan:</div><table class="mdl-data-table center-response mdl-js-data-table mdl-shadow--2dp"><thead><tr><th class="mdl-data-table__cell--non-numeric">Nama</th><th>Kode</th><th>Value</th><th class="mdl-data-table__cell--non-numeric">Deskripsi</th><th>Tanggal</th></tr></thead><tbody><tr><td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td><td>2019-06-27T17:00:00.000+00:00</td><td>25</td><td>Contoh Response</td><td>2019-06-27T17:00:00.000+00:00</td></tr><tr><td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td><td>2019-06-27T17:00:00.000+00:00</td><td>25</td><td>Contoh Response</td><td>2019-06-27T17:00:00.000+00:00</td></tr><tr><td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td><td>2019-06-27T17:00:00.000+00:00</td><td>25</td><td>Contoh Response</td><td>2019-06-27T17:00:00.000+00:00</td></tr></tbody></table></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-3"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><div class="mdl-textfield check-modif mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="check-modif"><label class="mdl-textfield__label"for="check-modif">Nama atau Kode barang</label></div><label class="mdl-radio radio-modif-name mdl-js-radio mdl-js-ripple-effect"for="update-name"id="radio-name"><input type="radio"id="update-name"class="mdl-radio__button"name="options"value="1"> <span class="mdl-radio__label">Nama</span></label><label class="mdl-radio radio-modif-description mdl-js-radio mdl-js-ripple-effect"for="update-description"id="radio-description"><input type="radio"id="update-description"class="mdl-radio__button"name="options"value="2"> <span class="mdl-radio__label">Deskripsi</span></label><script>$(function(){$("input#check-modif").keyup(function(){$(this).val()?($("label#radio-name").show(),$("label#radio-description").show()):($("label#radio-name").hide(),$("label#radio-description").hide())});var i=$("input#update-name"),d=$("input#update-description");i.add(d).on("click",function(){var d=this===i[0],e=d?$("#nama-div"):$("#deskripsi-div"),n=d?$("#deskripsi-div"):$("#nama-div");this.checked&&(e.fadeIn(),n.hide()),$("input").keyup(function(){$(this).val()?$("#check-modif-button").show():$("#check-modif-button").hide()}),$("#check-modif-button").click(function(){$("input").val(""),$(this).hide()})})})</script><div class="mdl-textfield input-modif-name mdl-js-textfield"id="nama-div"><input class="mdl-textfield__input"id="nama"name="nama"><label class="mdl-textfield__label"for="nama">Nama</label></div><div class="mdl-textfield input-modif-description mdl-js-textfield"id="deskripsi-div"><input class="mdl-textfield__input"id="deskripsi"name="deskripsi"><label class="mdl-textfield__label"for="deskripsi">Deskripsi</label></div><button class="mdl-button check-modif-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"id="check-modif-button">Modif</button></form><div class="response-modif">Berhasil modif barang.</div></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-4"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><script>$(function(){$("input#input-update").keyup(function(){$(this).val()?$("div#input-value-update").show():$("div#input-value-update").hide()}),$("input#input-value-update").keyup(function(){$(this).val()?$("button#button-update").show():$("button#button-update").hide()})})</script><div class="mdl-textfield update-input mdl-js-textfield mdl-textfield--floating-label"id="input-update"><input class="mdl-textfield__input"id="input-update"><label class="mdl-textfield__label"for="input-update">Nama atau Kode Barang</label></div><div class="mdl-textfield update-input-value mdl-js-textfield mdl-textfield--floating-label"id="input-value-update"><input class="mdl-textfield__input"pattern="-?[0-9]*(\.[0-9]+)?"id="input-value-update"><label class="mdl-textfield__label"for="input-value-update">Value Barang</label><span class="mdl-textfield__error">Input is not a number!</span></div><button class="mdl-button update-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"id="button-update">Update</button></form><div class="response-update">Berhasil modif barang.</div></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-5"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><script>$(function(){$("input#delete-barang").keyup(function(){$(this).val()?$("button#delete-barang").show():$("button#delete-barang").hide()})})</script><div class="mdl-textfield delete-barang mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="delete-barang"> <button id="delete-barang"class="mdl-button delete-button search-bottom mdl-js-button mdl-button--icon"><i class="material-icons search-icon">delete</i></button><label class="mdl-textfield__label"for="delete-barang">Nama atau Kode barang</label></div></form></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-6"><div class="page-content"></div></section></main></div></body></html><?php
    } else {
        header("Location: ../login");
        exit();
    }
} else {
    if (isset($_SESSION["username"]) && isset($_SESSION["password"])) {
?><html><head><link rel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons"><link href="https://fonts.googleapis.com/css?family=Russo+One&display=swap"rel="stylesheet"><link rel="stylesheet"href="../style/css/material.css"><link rel="stylesheet"href="../style/css/responsive.css"><script defer src="../style/js/material.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script></head><body><div class="mdl-layout mdl-js-layout mdl-layout--fixed-header"><header class="mdl-layout__header"><div class="mdl-layout__header-row"><a href="#!"><img class="image-responsive"src="../aksibox.png"></a><div class="mdl-layout-spacer"></div><nav class="mdl-navigation"><button id="logout"class="mdl-button mdl-js-button mdl-button--icon"><i class="material-icons icon-color">account_circle</i></button><script>$(function(){$("ul#logout").click(function(){<?php
        require '../aksibox/logout/AksiBoxLogout.php';
        $is = new AksiBoxLogout();
        $is->logout();
?>})})</script><ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect"for="logout"id="logout"><li class="mdl-menu__item">Logout</li></ul></nav></div><div class="mdl-layout__tab-bar mdl-js-ripple-effect"><a href="#scroll-tab-1"class="mdl-layout__tab is-active">Tambah Barang</a> <a href="#scroll-tab-2"class="mdl-layout__tab">Cari Barang</a> <a href="#scroll-tab-3"class="mdl-layout__tab">Modif Barang</a> <a href="#scroll-tab-4"class="mdl-layout__tab">Update Barang</a> <a href="#scroll-tab-5"class="mdl-layout__tab">Hapus Barang</a> <a href="#scroll-tab-6"class="mdl-layout__tab">Buat Invoice</a></div></header><main class="mdl-layout__content"><section class="mdl-layout__tab-panel is-active"id="scroll-tab-1"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><div class="mdl-textfield name-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="nameBarang"><label class="mdl-textfield__label"for="nameBarang">Nama Barang</label></div><div class="mdl-textfield code-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="codeBarang"><label class="mdl-textfield__label"for="codeBarang">Code Barang</label></div><div class="mdl-textfield value-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"pattern="-?[0-9]*(\.[0-9]+)?"id="valueBarang"><label class="mdl-textfield__label"for="valueBarang">Value Barang</label><span class="mdl-textfield__error">Input is not a number!</span></div><div class="mdl-textfield description-add mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="descriptionBarang"><label class="mdl-textfield__label"for="descriptionBarang">Deskripsi Barang</label></div><button class="mdl-button button-add mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"id="button-add">Add</button><div class="response-add">Berhasil menambahkan barang.</div></form></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-2"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><script>$(function(){$("input#search").keyup(function(){$(this).val()?$("button#search").show():$("button#search").hide()})})</script><div class="mdl-textfield search-box mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="search"> <button id="search"class="mdl-button search-button mdl-js-button mdl-button--icon"><i class="material-icons search-icon">search</i></button><label class="mdl-textfield__label"for="search">Nama atau Kode barang</label></div></form><div class="response-search">Data barang yang di temukan:</div><table class="mdl-data-table center-response mdl-js-data-table mdl-shadow--2dp"><thead><tr><th class="mdl-data-table__cell--non-numeric">Nama</th><th>Kode</th><th>Value</th><th class="mdl-data-table__cell--non-numeric">Deskripsi</th><th>Tanggal</th></tr></thead><tbody><tr><td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td><td>2019-06-27T17:00:00.000+00:00</td><td>25</td><td>Contoh Response</td><td>2019-06-27T17:00:00.000+00:00</td></tr><tr><td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td><td>2019-06-27T17:00:00.000+00:00</td><td>25</td><td>Contoh Response</td><td>2019-06-27T17:00:00.000+00:00</td></tr><tr><td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td><td>2019-06-27T17:00:00.000+00:00</td><td>25</td><td>Contoh Response</td><td>2019-06-27T17:00:00.000+00:00</td></tr></tbody></table></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-3"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><div class="mdl-textfield check-modif mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="check-modif"><label class="mdl-textfield__label"for="check-modif">Nama atau Kode barang</label></div><label class="mdl-radio radio-modif-name mdl-js-radio mdl-js-ripple-effect"for="update-name"id="radio-name"><input type="radio"id="update-name"class="mdl-radio__button"name="options"value="1"> <span class="mdl-radio__label">Nama</span></label><label class="mdl-radio radio-modif-description mdl-js-radio mdl-js-ripple-effect"for="update-description"id="radio-description"><input type="radio"id="update-description"class="mdl-radio__button"name="options"value="2"> <span class="mdl-radio__label">Deskripsi</span></label><script>$(function(){$("input#check-modif").keyup(function(){$(this).val()?($("label#radio-name").show(),$("label#radio-description").show()):($("label#radio-name").hide(),$("label#radio-description").hide())});var i=$("input#update-name"),d=$("input#update-description");i.add(d).on("click",function(){var d=this===i[0],e=d?$("#nama-div"):$("#deskripsi-div"),n=d?$("#deskripsi-div"):$("#nama-div");this.checked&&(e.fadeIn(),n.hide()),$("input").keyup(function(){$(this).val()?$("#check-modif-button").show():$("#check-modif-button").hide()}),$("#check-modif-button").click(function(){$("input").val(""),$(this).hide()})})})</script><div class="mdl-textfield input-modif-name mdl-js-textfield"id="nama-div"><input class="mdl-textfield__input"id="nama"name="nama"><label class="mdl-textfield__label"for="nama">Nama</label></div><div class="mdl-textfield input-modif-description mdl-js-textfield"id="deskripsi-div"><input class="mdl-textfield__input"id="deskripsi"name="deskripsi"><label class="mdl-textfield__label"for="deskripsi">Deskripsi</label></div><button class="mdl-button check-modif-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"id="check-modif-button">Modif</button></form><div class="response-modif">Berhasil modif barang.</div></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-4"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><script>$(function(){$("input#input-update").keyup(function(){$(this).val()?$("div#input-value-update").show():$("div#input-value-update").hide()}),$("input#input-value-update").keyup(function(){$(this).val()?$("button#button-update").show():$("button#button-update").hide()})})</script><div class="mdl-textfield update-input mdl-js-textfield mdl-textfield--floating-label"id="input-update"><input class="mdl-textfield__input"id="input-update"><label class="mdl-textfield__label"for="input-update">Nama atau Kode Barang</label></div><div class="mdl-textfield update-input-value mdl-js-textfield mdl-textfield--floating-label"id="input-value-update"><input class="mdl-textfield__input"pattern="-?[0-9]*(\.[0-9]+)?"id="input-value-update"><label class="mdl-textfield__label"for="input-value-update">Value Barang</label><span class="mdl-textfield__error">Input is not a number!</span></div><button class="mdl-button update-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"id="button-update">Update</button></form><div class="response-update">Berhasil modif barang.</div></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-5"><div class="page-content"><div class="mdl-grid center-items"><div class="mdl-cell mdl-cell--4-col"><form action="#"><script>$(function(){$("input#delete-barang").keyup(function(){$(this).val()?$("button#delete-barang").show():$("button#delete-barang").hide()})})</script><div class="mdl-textfield delete-barang mdl-js-textfield mdl-textfield--floating-label"><input class="mdl-textfield__input"id="delete-barang"> <button id="delete-barang"class="mdl-button delete-button search-bottom mdl-js-button mdl-button--icon"><i class="material-icons search-icon">delete</i></button><label class="mdl-textfield__label"for="delete-barang">Nama atau Kode barang</label></div></form></div></div></div></section><section class="mdl-layout__tab-panel"id="scroll-tab-6"><div class="page-content"></div></section></main></div></body></html><?php
    } else {
        header("Location: ../login");
        exit();
    }
}
?>

我试图在这样的仪表板页面上检查会话

if (isset($_SESSION["username"]) && isset($_SESSION["password"])) {}

还有这个

if (!empty($_SESSION["username"]) && !empty($_SESSION["password"])) {}

这是我的课:

<?php
class AksiBoxLogin
{
    public function login($username, $password)
    {
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_PORT => "3000",
            CURLOPT_URL => "http://localhost:3000/v1/login/account?username=" . $username . "&password=" . $password,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_HTTPHEADER => array(
                "Content-Type: application/json"
            )
        ));
        $response = curl_exec($curl);
        $error    = curl_error($curl);
        curl_close($curl);
        if ($error) {
            return $error;
        } else {
            return $response;
        }
    }
}

这是我的登录php:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require '../aksibox/login/AksiBoxLogin.php';
if (isset($_POST['username']) && isset($_POST['password'])) {
    $username = $_POST["username"];
    $password = $_POST["password"];
    $is       = new AksiBoxLogin();
    $response = $is->login($username, $password);
    $data     = json_decode($response, true);
    if ($data == 'Unauthorized') {
        print('Incorrect Username or Password');
    } else {
        @session_start();
        $_SESSION['username'] = $data['username'];
        $_SESSION['password'] = $data['password'];
        if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
            header("Location: ../dashboard");
            exit();
        }
    }
}
?>

这是我的登录页面:

<html>

<head>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link href="https://fonts.googleapis.com/css?family=Russo+One&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="../style/css/material.css">
    <link rel="stylesheet" href="../style/css/responsive.css">
    <script defer src="../style/js/material.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>

<body>
    <div class="mdl-grid center-items">
        <div class="mdl-cell mdl-cell--4-col"> <img class="image-login" src="../aksibox.png">
            <form method="post" action="../login/login.php">
                <script>
                    $(function() {
                        $("input#username").keyup(function() {
                            if ($(this).val()) {
                                $("div#password").show();
                            } else {
                                $("div#password").hide();
                            }
                        });
                        $("input#password").keyup(function() {
                            if ($(this).val()) {
                                $("button#login-button").show();
                            } else {
                                $("button#login-button").hide();
                            }
                        });
                    });
                </script>
                <div class="mdl-textfield input-username mdl-js-textfield mdl-textfield--floating-label" id="username">
                    <input class="mdl-textfield__input" type="text" name="username" id="username">
                    <label class="mdl-textfield__label" for="username">Username</label>
                </div>
                <div class="mdl-textfield input-password mdl-js-textfield mdl-textfield--floating-label" id="password">
                    <input class="mdl-textfield__input" type="password" name="password" id="password">
                    <label class="mdl-textfield__label" for="password">Password</label>
                </div>
                <button type="submit" class="mdl-button login-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" name="login" id="login-button">Login</button>
            </form>
        </div>
    </div>
</body>

</html>

0 个答案:

没有答案