How to fill out a person's name, email address and SUNetID on a form behind WebAuth with PHP
From Web Services Wiki
Contents |
Problem
You want to pre-fill a form behind WebAuth with the currently logged in user's name, SUNetID, and e-mail address.
Solution
Use environment variables set by Apache's WebAuth LDAP module
A person's name, SUNetID and email address are automatically set in environment variables for you by Apache when behind WebAuth.
$name = $_ENV['WEBAUTH_LDAP_DISPLAYNAME']; $sunetid = $_ENV['WEBAUTH_USER']; $email = $_ENV['WEBAUTH_LDAP_MAIL'];
Sample usage
It is often useful to pre-fill form fields to make your application more intelligent and reduce the burden of your users.
<form action="save.php" method="post"> <p><label for="name">Name:</label><br/> <input type="text" name="name" id="name" value="<?=htmlspecialchars($name)?>" /></p> <p><label for="sunetid">SUNetID:</label><br/> <input type="text" name="sunetid" id="sunetid" value="<?=htmlspecialchars($sunetid)?>" /></p> <p><label for="email">E-mail address:</label><br/> <input type="text" name="email" id="email" value="<?=htmlspecialchars($email)?>" /></p> <input type="submit" name="submit" value="Save" /> </form>

