I have one. It takes 3 values from a form, rep_id, email, password. You can modify this if you need. Basically it checks for missing values, verify they are a valid user, and sets two cookies, one for their rep_id, and the other to use for authorization on all pages they need to be logged in to see.
<?
//check to see if all fields have values
if((!$POST[rep_id]) || (!$POST[email]) || (!$_POST[password])) {
header("Location: http://address.com/ofyourloginpage.html");
exit;
}
//check to see if rep is valid by counting rows where all three variables match database.
$connection = @mysql_connect("localhost", "username", "password");
$db = @mysql_select_db(database_name, $connection);
$sql = "SELECT * FROM reps WHERE id = '$POST[rep_id]' AND email = '$POST[email]' AND pass = password('$_POST[password]')";
$result = @($sql, $connection);
$num = mysql_num_rows($result);
if ((!$result)||($num!=1)) {
header( "Location: http://address.com/ofyourloginpage.html");
exit;
} else {
$rep_id = $_POST[rep_id];
//if rep is valid set rep id cookie and auth ok
setcookie(rep_id, $rep_id);
setcookie(auth, "ok");
$msg = "you are now logged in.";
}