Skip to main content
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481
added 106 characters in body
Source Link

EDIT: I'm aware that passwords should never be stored in plain text. I'll be fixing that soon.


EDIT: I'm aware that passwords should never be stored in plain text. I'll be fixing that soon.


fixed incorrect variable name in the JS on login.php
Source Link
<?PHP
require_once('_classes.php');
$db = new db_controller(); // use this globally for all DB work.
$session = new sessionHandler('LOGIN');
?>
<html>

<body>

<div>
    <div>
        <div>
            <img src="img/logo.png">
        </div>

        <h3>Welcome to myApp</h3>
        <p>Login in to see it in action!</p>

        <form id="loginForm">
            <input name="username">
            <input type="password" name="password">
            <button type="submit">Login</button>
        </form>
    </div>
</div>

<!-- scripts -->
<script src="js/jquery-2.1.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
    $('#loginForm').submit(function (e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: '_functions.php?function=login',
            data: $('form').serialize(),
            dataType: 'JSON',
            success: function (data) {
                if (data['success']) {
                    // determine if the user has been redirected from another
                    // page prior to getting to the login page, if so, send them
                    // back to it instead of the default page
                    var urlParams = {};window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (str, key, value) {params[key]urlParams[key] = value;                    });
                    var redirectPage = decodeURIComponent(urlParams['d']);

                    if (redirectPage == 'undefined') {
                        // if there is not redirect parameter on the URL,
                        // then send them to the default page
                        redirectPage = data['redirectPage'];
                    }

                    window.location.replace(redirectPage);
                } else {
                    alert(data['error']);
                }
            }
        });
    });

</script>

</body>

</html>
<?PHP
require_once('_classes.php');
$db = new db_controller(); // use this globally for all DB work.
$session = new sessionHandler('LOGIN');
?>
<html>

<body>

<div>
    <div>
        <div>
            <img src="img/logo.png">
        </div>

        <h3>Welcome to myApp</h3>
        <p>Login in to see it in action!</p>

        <form id="loginForm">
            <input name="username">
            <input type="password" name="password">
            <button type="submit">Login</button>
        </form>
    </div>
</div>

<!-- scripts -->
<script src="js/jquery-2.1.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
    $('#loginForm').submit(function (e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: '_functions.php?function=login',
            data: $('form').serialize(),
            dataType: 'JSON',
            success: function (data) {
                if (data['success']) {
                    // determine if the user has been redirected from another
                    // page prior to getting to the login page, if so, send them
                    // back to it instead of the default page
                    var urlParams = {};window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (str, key, value) {params[key] = value;                    });
                    var redirectPage = decodeURIComponent(urlParams['d']);

                    if (redirectPage == 'undefined') {
                        // if there is not redirect parameter on the URL,
                        // then send them to the default page
                        redirectPage = data['redirectPage'];
                    }

                    window.location.replace(redirectPage);
                } else {
                    alert(data['error']);
                }
            }
        });
    });

</script>

</body>

</html>
<?PHP
require_once('_classes.php');
$db = new db_controller(); // use this globally for all DB work.
$session = new sessionHandler('LOGIN');
?>
<html>

<body>

<div>
    <div>
        <div>
            <img src="img/logo.png">
        </div>

        <h3>Welcome to myApp</h3>
        <p>Login in to see it in action!</p>

        <form id="loginForm">
            <input name="username">
            <input type="password" name="password">
            <button type="submit">Login</button>
        </form>
    </div>
</div>

<!-- scripts -->
<script src="js/jquery-2.1.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
    $('#loginForm').submit(function (e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: '_functions.php?function=login',
            data: $('form').serialize(),
            dataType: 'JSON',
            success: function (data) {
                if (data['success']) {
                    // determine if the user has been redirected from another
                    // page prior to getting to the login page, if so, send them
                    // back to it instead of the default page
                    var urlParams = {};window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (str, key, value) {urlParams[key] = value;                    });
                    var redirectPage = decodeURIComponent(urlParams['d']);

                    if (redirectPage == 'undefined') {
                        // if there is not redirect parameter on the URL,
                        // then send them to the default page
                        redirectPage = data['redirectPage'];
                    }

                    window.location.replace(redirectPage);
                } else {
                    alert(data['error']);
                }
            }
        });
    });

</script>

</body>

</html>
Remove square brackets around title, change triple equals to triple hyphen for a proper line break
Source Link
Dan
  • 3.8k
  • 24
  • 39
Loading
Source Link
Loading