<?PHP

# This is an example of authenticating in a PHP script against an
# Active Directory (Windows) server.  The HTML form which calls this
# PHP script is sending over the two variables "username" and "userpass".
# Rename this file to .PHP to use it, of course.

import_request_variables("P","form_");

$escaped_username escapeshellcmd(strtolower($form_username));
$escaped_userpass escapeshellcmd($form_userpass);

# First let's see if this is a valid username/password.
exec("smbclient \\\\\\\\servername\\\\netlogon $escaped_userpass -U $escaped_username -c quit",$junk_array,$result_code);

# If we didn't get a return code of 0, then display an error page with
# a link to return to the web site or the login page.
if ($result_code)
  {
  echo 
"<HTML><HEAD><TITLE>Login Error</TITLE></HEAD>\n";
  echo 
"<BODY><H2>Login Error</H2><HR>\n";
  echo 
"There was a problem with your username and password.<BR>\n";
  echo 
"Please hit the BACK button to try again.\n";
  echo 
"</BODY></HTML>\n";
  exit();
  }

# Here we can do something like set a cookie and then redirect to a menu.
setcookie("Username",$form_username);
header("Location: clh_menu.php");

?>