I thought that I am calling another page request (even though it is the same page).
I am using and LDAP function to authenticate from Active Directory. If the user is not authenticated , then the code shows the form on the bottom. Otherwise it shows $authenticated.
Here's the Code:
<?php
session_start();
header("Cache-control: private");
require('../includes/configure.php');
setcookie("user", $_GET['user'], time()+3600);
?>
<html>
<head>
<title>HR New Record Form</title>
</head>
<?php require_once("../includes/adLDAP.php");
// We've Authenticated and also entered our search information
if ($logintest || ($SESSION['user'] && $SESSION['pass'])) { // We've entered our AD Credentials, verify.
if (!$_SESSION['user']) {
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
}
$adldap = new adLDAP();
if ($adldap -> authenticate($user,$pass)){
if ($adldap -> user_ingroup($user,"Domain Users")){
$authenticated = 1;
} else {
print "You are not authorized to complete this request. If this is in error please contact IT.<br /><br /><a href='insert.php'>Retry.</a>\n";
$_SESSION['user'] = FALSE;
$_SESSION['pass'] = FALSE;
}
} else {
$_SESSION['user'] = FALSE;
$_SESSION['pass'] = FALSE;
print "Incorrect Username or Password, please try again.<br /><br /><a href='insert.php'>Retry.</a>\n";
}
if ($authenticated) { // We've completed AD Authentication ?>
<body>
<table width="393" border="0" align="center">
<tr>
<td width="206">Cookie info: </td>
<td width="197"><? echo $_COOKIE['user']; ?></td>
</tr>
</table>
<?php
}
} else { // We need to authenticate the user ?>
<span class='WarningText'>[ This Area is Restricted to Managers and Administrators. ]</span><p>Please Login to Continue.</p>
<form method='GET' action='<? echo $_SERVER['REQUEST_URI']; ?>'>
<table><tr>
<td>Username:</td><td><input type='text' name='user' value=''> (Same as your windows login)</td></tr>
<tr><td>Password:</td><td><input type='password' name='pass'></td></tr></table>
<input type='hidden' name='logintest' value='1'>
<br /><input type='submit' value='Submit'>
<? } ?>
</body>
</html>