Skip to content

Instantly share code, notes, and snippets.

@pfeilbr
Created June 9, 2014 13:01
Show Gist options
  • Save pfeilbr/b01325edf977c3510f1f to your computer and use it in GitHub Desktop.
Save pfeilbr/b01325edf977c3510f1f to your computer and use it in GitHub Desktop.
login handler
<?php
$loggedin = false;
$error = false;
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$userName=addslashes($_POST['userName']);
$userPwd=addslashes($_POST['userPwd']);
$sql="SELECT * FROM users WHERE userName='$userName' and userPwd='$userPwd'";
$result=mysql_query($sql);
// begin - new code
if ($result) {
$count = mysql_num_rows($result);
if ($count == 1) {
$loggedin = true;
session_register("userName");
$_SESSION['userName']=$userName;
}
}
if ($loggedin == false) {
$error="Your Login Name or Password is invalid";
}
// end - new code
define('TITLE', 'Customer Login');
include('templates/header.html');
if ($error) {
print '<p class="error">' . $error . '</p>';
}
if ($loggedin) {
header("Location:productSummaryPage.php");
} else {
print '<h2>Login Form</h2>
<form action="customerLogin.php" method="post">
<p><label>Username: <input type="text" name="userName" /></label></p>
<p><label>Password: <input type="password" name="userPwd" /></label></p>
<p><input type="submit" name="submit" value="Log In!" /></p>
</form>';
}
include('templates/footer.html');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment