The code below gets the username/password and runs it thru the backend.php script.
<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#login_form").submit(function() {
var unameval = $("#username").val();
var pwordval = $("#password").val();
$.post("backend.php", { username: unameval,
password: pwordval }, function(data) {
$("#status p").html(data);
});
return false;
});
});
</script>
</head>
<body>
<?php
if(isset($_SESSION['user_session'])) {
print '<p>user '.$_SESSION['user_session'].' logged in</p>';
} else { ?>
<form id="login_form" method="post">
<p>Username: <input type="text" id="username" name="username" /></p>
<p>Password: <input type="password" id="password" name="password" /></p>
<p><input type="submit" value="Login" /></p>
</form>
<div id="status">
<p></p>
</div> <?php
}?>
</body>
</html>
It authenticates the user properly, but what I want it to is hide the form once successful.
Here is what the page looks like before the form is submitted: http://grab.by/3hoH
Here is the page after the form was successfully submitted: http://grab.by/3hoR
I think I need to run some javascript to check for success, then if success, do not display form, if !success, display form.
I am unsure on how to do that, if that is the case.
backend.php code
<?php
session_start();
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once('adLDAP.php');
//header('Content-type: text/json');
$adldap = new adLDAP();
if(isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password']; // associated password
// connect to ldap server
$authUser = $adldap->authenticate($username, $password);
if ($authUser === true) {
print "<p>authuser true</p>";
$_SESSION['user_session'] = $username;
if(isset($_SESSION['user_session'])) {
print "<p>session is set</p>";
}
}
else {
print "<p>User authentication unsuccessful</p>";
}
}
?>