1 <?php 2 //log them out 3 $logout = $_GET['logout']; 4 if ($logout == "yes") { //destroy the session 5 session_start(); 6 $_SESSION = array(); 7 session_destroy(); 8 } 9 10 //force the browser to use ssl (STRONGLY RECOMMENDED!!!!!!!!) 11 if ($_SERVER["SERVER_PORT"] != 443){ 12 header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); 13 exit(); 14 } 15 16 //you should look into using PECL filter or some form of filtering here for POST variables 17 $username = strtoupper($_POST["username"]); //remove case sensitivity on the username 18 $password = $_POST["password"]; 19 $formage = $_POST["formage"]; 20 21 if ($_POST["oldform"]) { //prevent null bind 22 23 if ($username != NULL && $password != NULL){ 24 //include the class and create a connection 25 include (dirname(__FILE__) . "/../src/adLDAP.php"); 26 try { 27 $adldap = new adLDAP(); 28 } 29 catch (adLDAPException $e) { 30 echo $e; 31 exit(); 32 } 33 34 //authenticate the user 35 if ($adldap->authenticate($username, $password)){ 36 //establish your session and redirect 37 session_start(); 38 $_SESSION["username"] = $username; 39 $_SESSION["userinfo"] = $adldap->user()->info($username); 40 $redir = "Location: https://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/menu.php"; 41 header($redir); 42 exit; 43 } 44 } 45 $failed = 1; 46 } 47 48 ?> 49 50 <html> 51 <head> 52 <title>adLDAP example</title> 53 </head> 54 55 <body> 56 57 This area is restricted.<br> 58 Please login to continue.<br> 59 60 <form method='post' action='<?php echo $_SERVER["PHP_SELF"]; ?>'> 61 <input type='hidden' name='oldform' value='1'> 62 63 Username: <input type='text' name='username' value='<?php echo ($username); ?>'><br> 64 Password: <input type='password' name='password'><br> 65 <br> 66 67 <input type='submit' name='submit' value='Submit'><br> 68 <?php if ($failed){ echo ("<br>Login Failed!<br><br>\n"); } ?> 69 </form> 70 71 <?php if ($logout=="yes") { echo ("<br>You have successfully logged out."); } ?> 72 73 74 </body> 75 76 </html> 77